Forum Moderators: bakedjake

Message Too Old, No Replies

Automatic HTTP Transfers

         

Langers

1:03 pm on Jun 3, 2005 (gmt 0)

10+ Year Member



I need to find a way to do automatic scheduled file transfers from a website (via http) to my own host.

However, I'm not sure of the best way of doing this. I have made a php script to do the job manually but some of the files are quite large and tend to cause browser timeouts.

I am hosted on a redhat linux box and have access to Cron.

Any suggestions?

bakedjake

1:07 pm on Jun 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You can script wget or ncftp from the command line very easily.

mcavic

4:01 pm on Jun 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try wget or curl. Both are easy to use. Or if you have neither, lynx with the -source option.

pauluskc

10:09 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



From the PHP documentation on the fread() function:

[us2.php.net...]

[.....]

<?php
$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
?>

You can then have it dump the contents of $contents using fwrite():

[us2.php.net...]

one last option: file_get_contents() along with fwrite():

[us2.php.net...]

Haven't tried it that way, but it should be ok.

Make sure that when you put this stuff in a PHP file for running with cron that you have it not output anything (use @ on the functions, etc.) and do you own error trapping/log writing/progress notification/whatever. Or you could get a ton of annoying emails that collect in the account's default email bin.

To run PHP scripts with cron: php -f filname.php

Have fun!