chaiwei Posted December 2, 2009 Share Posted December 2, 2009 Hi, I want to know is it possible to copy the file from 1 server to another server by using php scripts? In my case: I plan to use mysqldump to backup my database inside a sql file, so the generated backup file should be in the server. Next I plan to use cron to run the backup daily and transfer the sql file(backup) to another server. If It is not a server,but local pc, will it be done? because I plan to use script download to a local pc folder and sharing the folder so that user can copy the file into their thumbdrive and can bring it home. Is there any way to let me do that? Quote Link to comment https://forums.phpfreaks.com/topic/183707-copy-file-from-server-to-another-server-using-php/ Share on other sites More sharing options...
trq Posted December 2, 2009 Share Posted December 2, 2009 A few ways you could do this. If your server has an ftp server setup you could use the ftp extension. If you have shell access you could use scp via exec If you have shell access you could simply map a remote drive using sshfs or nfs. I don't see why you need to use php for this. Quote Link to comment https://forums.phpfreaks.com/topic/183707-copy-file-from-server-to-another-server-using-php/#findComment-969597 Share on other sites More sharing options...
chaiwei Posted December 2, 2009 Author Share Posted December 2, 2009 Hi, Because I only know php.. I should use shell script better? Quote Link to comment https://forums.phpfreaks.com/topic/183707-copy-file-from-server-to-another-server-using-php/#findComment-969599 Share on other sites More sharing options...
trq Posted December 2, 2009 Share Posted December 2, 2009 A shell script would be quite capable yes. Quote Link to comment https://forums.phpfreaks.com/topic/183707-copy-file-from-server-to-another-server-using-php/#findComment-969601 Share on other sites More sharing options...
chaiwei Posted December 2, 2009 Author Share Posted December 2, 2009 Thanks.. why shell script is better? Any advantage over php? Quote Link to comment https://forums.phpfreaks.com/topic/183707-copy-file-from-server-to-another-server-using-php/#findComment-969602 Share on other sites More sharing options...
JonnoTheDev Posted December 2, 2009 Share Posted December 2, 2009 Thanks.. why shell script is better? Any advantage over php? Because most of the commands required in this operation such as mysqldump, sftp, ftp, scp, etc are all command line programs, so why use php? Quote Link to comment https://forums.phpfreaks.com/topic/183707-copy-file-from-server-to-another-server-using-php/#findComment-969603 Share on other sites More sharing options...
trq Posted December 2, 2009 Share Posted December 2, 2009 Thanks.. why shell script is better? Any advantage over php? You just don't need php is all. Its just as easy to write your shell commands directly into your crontab. eg; stamp=date +"%m-%d-%Y-%H:%M:%S" 0 5 * * * /usr/bin/mysqldump --opt databasename > /tmp/$stamp-dump.sql && scp /tmp/$stamp-dump.sql remotemachine:/path/to/backups/ && rm /tmp/$stamp-dump.sql Done Quote Link to comment https://forums.phpfreaks.com/topic/183707-copy-file-from-server-to-another-server-using-php/#findComment-969604 Share on other sites More sharing options...
chaiwei Posted December 2, 2009 Author Share Posted December 2, 2009 Thanks a lot... Quote Link to comment https://forums.phpfreaks.com/topic/183707-copy-file-from-server-to-another-server-using-php/#findComment-969606 Share on other sites More sharing options...
chaiwei Posted December 2, 2009 Author Share Posted December 2, 2009 What if I want to transfer the file to one of the window pc on my LAN? Could I do that? Example. After the cron run every midnight to backup the database, It will generate a sql file inside the server. I want to transfer the sql file to a LAN (window) pc's sharing folder. example the pc name was pc01, its IPv4 in LAN was 192.168.1.3 the server used to generate sql file on LAN was 192.168.2.6 So I used sftp pc01@192.168.1.3 ? Quote Link to comment https://forums.phpfreaks.com/topic/183707-copy-file-from-server-to-another-server-using-php/#findComment-969635 Share on other sites More sharing options...
JonnoTheDev Posted December 2, 2009 Share Posted December 2, 2009 If both servers can talk to each other over your lan then just mount a share on the linux machine to the windows machine. Copy the file to the share. Quote Link to comment https://forums.phpfreaks.com/topic/183707-copy-file-from-server-to-another-server-using-php/#findComment-969640 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.