EagleAmerican Posted July 2, 2008 Share Posted July 2, 2008 I'm trying to make a script to download all files from an ftp directory to my hosting. I know I need to use a loop but not sure where to go from here. Any help appreciated. <?php $ftp_server = ""; $uname = ""; //Enter your ftp username here. $pwd = ""; //Enter your ftp password here. $directory = "" //Enter the dir of the files on the server here. $connection = ftp_connect($ftp_server) or die("Error connecting to $ftp_server"); $login = ftp_login($connection, $uname, $pwd); if (ftp_chdir($connection, $directory)) { echo "Changed directory to: " . ftp_pwd($connection) . "\n"; } else { echo "Error while changing directory!\n"; } ftp_pasv($connection,TRUE); $count = count(ftp_nlist($connection, ".")); ftp_close($connection); ?> Link to comment https://forums.phpfreaks.com/topic/112984-solved-download-all-files-from-directory/ Share on other sites More sharing options...
lemmin Posted July 2, 2008 Share Posted July 2, 2008 I think this would work: <?php $ftp_server = ""; $uname = ""; //Enter your ftp username here. $pwd = ""; //Enter your ftp password here. $directory = "" //Enter the dir of the files on the server here. $connection = ftp_connect($ftp_server) or die("Error connecting to $ftp_server"); $login = ftp_login($connection, $uname, $pwd); if (ftp_chdir($connection, $directory)) { echo "Changed directory to: " . ftp_pwd($connection) . "\n"; } else { echo "Error while changing directory!\n"; } ftp_pasv($connection,TRUE); $files = ftp_nlist($connection, "."); foreach ($files as $file) { $newFile = fopen($file, 'w'); ftp_nb_fget($connection, $newFile, $file, FTP_BINARY); fclose($newFile); } ftp_close($connection); ?> Link to comment https://forums.phpfreaks.com/topic/112984-solved-download-all-files-from-directory/#findComment-580404 Share on other sites More sharing options...
EagleAmerican Posted July 2, 2008 Author Share Posted July 2, 2008 Parse error: syntax error, unexpected T_VARIABLE in /home/sites/site/public_html/ftp/ftpdl.php on line 7 Link to comment https://forums.phpfreaks.com/topic/112984-solved-download-all-files-from-directory/#findComment-580420 Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 Missing ; on line 5. Link to comment https://forums.phpfreaks.com/topic/112984-solved-download-all-files-from-directory/#findComment-580436 Share on other sites More sharing options...
upgrader Posted July 5, 2008 Share Posted July 5, 2008 Hi, Im trying to get this script to work on my server but it doesn't download any files. The script echoes: Changed directory to: /my/directory Running PHP 5.2.1 Thanks for any help Link to comment https://forums.phpfreaks.com/topic/112984-solved-download-all-files-from-directory/#findComment-582170 Share on other sites More sharing options...
upgrader Posted July 5, 2008 Share Posted July 5, 2008 I've just tried a few things: FTP_PASV FALSE and FTP_ASCII But neither work still :S Link to comment https://forums.phpfreaks.com/topic/112984-solved-download-all-files-from-directory/#findComment-582289 Share on other sites More sharing options...
upgrader Posted July 5, 2008 Share Posted July 5, 2008 Progress: I got the script working by doing php ftp.php in the shell and it downloaded all the files, However most of the files were 2.9K and the rest 1.4K yet on the FTP server they were over 5mb for most. Any ideas how to get it to download the whole file? Link to comment https://forums.phpfreaks.com/topic/112984-solved-download-all-files-from-directory/#findComment-582298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.