How to FTP Multiple Files?
Posted: Sat Oct 11, 2008 3:30 pm
I have a PHP script I've been using to DL a file to my server for further use and it works great. But I now need to DL multiple files from the same server and I need help setting up a way to do this. I would like to be able to call to a txt file with a list of the files I need and then download each in turn to the server
All the files I need to DL are in the same remote directory and they will be all placed in the same local directory on my server. Any help or guidance would be appreciated, thanks.
Code: Select all
$ftp_server = "server.com";
$ftp_user_name = "name";
$ftp_user_pass = "password";
$source_file = "/dir/file1.zip";
$destination_file = "/home/public_html/dl/file1.zip";
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed to $ftp_server as $ftp_user_name.<br />";
exit;
} else {
echo "Connected to $ftp_server successfully as $ftp_user_name.<br />";
}
$download = ftp_get($conn_id, $destination_file, $source_file, FTP_BINARY);
if (!$download) {
echo "FTP download has failed!";
} else {
echo "Downloaded $source_file from $ftp_server as $destination_file";
}
fclose($fp);