PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
$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);
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.
Im not going to write the code for you but I will tell you how to do it.
Simply write a script that gets each line in your textfile and put them into a variable then run a foreach() on that array with the ftp download command in it. It should download each file in the textfile if you are in the right folder.
I wish I could just write that script but the code I posted is something I found that I was able to use by changing the variables. I have no code skills other than being able to find examples of existing code and then by trial and error attempt to make it work. If anyone could post an example I might be able to work through it and make it work. Thanks