lefenix Posted March 27, 2006 Share Posted March 27, 2006 hi All,Can someone please help me with this - Need to write a PHP script that will download a file from a remote loaction once a week.So, if I could schedule a date that my computer will connect to a remote website, download the file and replace the existing file in a local folder on my computer - say...every 10 days I would be forever gratefull and could possibly compenste in some way that this forum would allow.Thanks!!!Fenix Quote Link to comment https://forums.phpfreaks.com/topic/5962-remote-file-download/ Share on other sites More sharing options...
craygo Posted March 27, 2006 Share Posted March 27, 2006 if you have ftp to the remote site you could just connect and download the file. Or even schedule a task in task manager to get the file.You can create 2 fileexamplefile name ftpdown.bat[code]ftp -s:c:\getfiles.txt[/code]This will tell ftp to use a file called getfiles.txtgetfiles.txt[code]open (ipaddress or domain name here)usernamepasswordcd folder/where/file/isbinary or asciiget remote_file local_fileclosequit[/code]Now just schedule a task in your task manager at the time you want and all setRay Quote Link to comment https://forums.phpfreaks.com/topic/5962-remote-file-download/#findComment-21351 Share on other sites More sharing options...
lefenix Posted March 27, 2006 Author Share Posted March 27, 2006 Thanks for the feedback. But I'm working in a Linux enviro, thus the need to script it.Any ideas from that standpoint?Fenix Quote Link to comment https://forums.phpfreaks.com/topic/5962-remote-file-download/#findComment-21360 Share on other sites More sharing options...
craygo Posted March 28, 2006 Share Posted March 28, 2006 If you have access to cron jobs you can start a php file from there. I am not sure what the command is but it is in this forum somewhere. As far as the script goes.[code]<?// Set FTP Variables$ftp_server = "domain or ip here";$ftp_user = "username";$ftp_pass = "password";$remote_folder = "remote/folder/here/";$local_folder = "local/folder/here/";$filename = "filenamehere";// Delete file first if you want to avoid errorsif (file_exists($local_folder.$filename)){unlink($filename);}// Connect to FTP Server$conn_id = ftp_connect($ftp_server, 21); $login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);// check connection to test, can comment out laterif ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!"; echo "Attempted to connect to $ftp_server for user $ftp_user"; exit; } else { echo "Connected to $ftp_server, for user $ftp_user";// Get the file ftp_get($conn_id, $local_folder.$filename, $remote_folder.$filename, FTP_ASCII); }ftp_close($conn_id);?>[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/5962-remote-file-download/#findComment-21579 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.