d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Php Help Downloading
12Next
Add Reply New Topic New Poll
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 2 2014 01:27am
so im trying to move my files from one server to another server

im trying to use this

file_put_contents("FILENAME", fopen("WEBSITE", 'r'));

but it gives me this error

PHP Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION

any help..
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Nov 2 2014 02:03am
Is this for backing up data or for other reasons?

If this is for backing up data I suggest using RSYNC instead.

Also that function doesn't do what you think it does. You are never going to be able to push data from one server to another using that function like you seem to be trying. You are better off pulling the data from one server to another.

The reason why you cannot "push" files to another server is because you can't open a file handle on the other server to write the file. Fopen() only opens a file handle to the page you point to, in which to grab the source code or file contents on that server.

If you are trying to do something else please clarify.

Edit:: Also try changing the single quotes to double quotes. If php is like C, single quotes denotes char where as fopen() wants a string for it's mode.

This post was edited by AbDuCt on Nov 2 2014 02:06am
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 2 2014 02:20am
i have a bash file, set up to zip up certain folders every 12 hours, and moves it to /var/www/html/backups. Im setting up a backup server to run a script with php to download the zip from another server
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Nov 2 2014 01:02pm
Quote (gamemaste789 @ Nov 2 2014 04:20am)
i have a bash file, set up to zip up certain folders every 12 hours, and moves it to /var/www/html/backups. Im setting up a backup server to run a script with php to download the zip from another server


Use RSYNC then. It was meant for backing up files/directories. It works over SSH so all your files are encrypted while being transferred over the wire, and RSYNC only transfers files which have changes made to them (you need another flag to delete files which no longer exist in the backup automatically). This means once you do your first initial backup, any other backup will only send the pieces of the file which has been changed. For example if you changed 2 words in the source code, it will detect that and onyl send the two words to patch the file on the other server instead of sending the whole file.

Code
rsync -rchvzP --stats username@hostname.com:/var/www/backups /my/local/folder/to/move/to/on/this/box


Run it on the server you want to download your files to.

Alternatively you can push files onto the other server instead of pulling. I would read the man page as there are a ton of options, some more specific than others such as also transferring over file permissions (uid, gid) and symlinks/hardlinks and the like.

Trying to use php to transfer your backups is retarded.

If you want a good backup scheme use RSYNC in a bash script and setup a cronjob to execute it every 12 hours on the box you wish to download the backups to. Or if you want to isolate everything to one box run it on the box with the backups located and use a "push" method to send the files to the other server.

This post was edited by AbDuCt on Nov 2 2014 01:04pm
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 2 2014 03:46pm
well the backup server, i dont have full access over... its a shared backup server. so i have to use things already on the server and the only thing on the server is php and rsync isnt installed D:
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Nov 2 2014 03:55pm
Quote (gamemaste789 @ Nov 2 2014 05:46pm)
well the backup server, i dont have full access over... its a shared backup server. so i have to use things already on the server and the only thing on the server is php and rsync isnt installed D:


There are other applications which may be installed. lftp has a mirror option which only transfers files which have a newer creation or modified data than the ones in it's directories. The downsize to this is that it is not encrypted.

There are also other solutions of it is only a small number of files like scp and sftp which run over ssh and can grab the files to transfer them over. They would transfer over the entire files as well.

If you have ssh access you can simply move the binary for rsync over to your home dir and chmod it and use it tbh. https://rsync.samba.org/

If you wish to continue using php for such a task you will have to do this:
Code
1) pull all file links from the web facing directory
2) iterate over all these links
3) while iterating regex or substring out the filename for use in file_puts_content
4) using file_puts_content insert the filename you pulled from the link as well as the link to the file inside of fopen.


The function file_puts_content doesn't open up the root directory and download everything in it, you must provide a link to each individual file.

This all has to be done from the server downloading the files, you cant go the other way around IE the server hosting the backups cant force them into the other server.

This post was edited by AbDuCt on Nov 2 2014 03:56pm
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 2 2014 04:06pm
I can do that, i just need the simple coding...
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 2 2014 05:04pm
I was going to use it like this

file_put_contents("backup-11.3.14.5.zip", fopen("192.168.2.1/backup/backup-11.3.14.5.zip", 'r'));


but its not working...
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Nov 2 2014 06:00pm
Quote (gamemaste789 @ Nov 2 2014 07:04pm)
I was going to use it like this

file_put_contents("backup-11.3.14.5.zip", fopen("192.168.2.1/backup/backup-11.3.14.5.zip", 'r'));


but its not working...


just use wget or axel. you must have some sort of transfer tool installed...

wget, axel, ncat, nc, netcat, lftp, scp, sftp, rsync.

Why are you continually trying to use php for this.
Member
Posts: 30,168
Joined: Jun 10 2010
Gold: 1,157.00
Nov 2 2014 06:08pm
bc i have webaccess and thats all...
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll