Jump to content


Photo

Remote File Download


  • Please log in to reply
3 replies to this topic

#1 lefenix

lefenix
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 March 2006 - 08:58 PM

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

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 27 March 2006 - 10:01 PM

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
ftp -s:c:\getfiles.txt
This will tell ftp to use a file called getfiles.txt

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

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

Ray

#3 lefenix

lefenix
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 March 2006 - 10:46 PM

Thanks for the feedback. But I'm working in a Linux enviro, thus the need to script it.
Any ideas from that standpoint?

Fenix

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 28 March 2006 - 02:07 PM

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.
<?
// 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);
?>

Ray




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users