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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.