Jump to content

Remote File Download


lefenix

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/5962-remote-file-download/
Share on other sites

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 file

example

file name ftpdown.bat
[code]ftp -s:c:\getfiles.txt[/code]
This will tell ftp to use a file called getfiles.txt

getfiles.txt
[code]open (ipaddress or domain name here)
username
password
cd folder/where/file/is
binary or ascii
get remote_file local_file
close
quit
[/code]

Now just schedule a task in your task manager at the time you want and all set

Ray
Link to comment
https://forums.phpfreaks.com/topic/5962-remote-file-download/#findComment-21351
Share on other sites

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 errors
if (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 later
if ((!$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
Link to comment
https://forums.phpfreaks.com/topic/5962-remote-file-download/#findComment-21579
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.