Jump to content

Archived

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

lefenix

Remote File Download

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

Share this post


Link to post
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

Share this post


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

Fenix

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.