I'm trying using this script to download a zip file from an FTP source (on localhost it works but not on the live server form OVH).
When running it on a live server I get instantly this:
- successfully connected to the ftp server!
- logged in successfully!
- Error while downloading from ... .
- Connection closed Successfully!
So all the connection are good but it get stuck on downloading the file.
What could be the issue, or how could I get some error reports for this?
Some thinks that I have checked:
- FTP support enabled (in PHP)
- permission for the folder is 777;
- the port is open (21);
- php max execution is long (300);
- the firewall provided by the hosting is disabled (I don't have any control over if is just on/off)
What else could it be?
// Connect to FTP server
// Use a correct ftp server
$ftp_server = "localhost";
// Use correct ftp username
$ftp_username="user";
// Use correct ftp password corresponding
// to the ftp username
$ftp_userpass="user";
// Establishing ftp connection
$ftp_connection = ftp_connect($ftp_server, 21)
or die("Could not connect to $ftp_server");
if( $ftp_connection ) {
echo "successfully connected to the ftp server!";
// Logging in to established connection
// with ftp username password
$login = ftp_login($ftp_connection,
$ftp_username, $ftp_userpass);
if($login) {
// Checking whether logged in successfully
// or not
echo "<br>logged in successfully!";
// Name or path of the localfile to
// where the file to be downloaded
$local_file = "file.zip";
// Name or path of the server file to
// be downoaded
$server_file = "file.zip";
// Downloading the specified server file
if (ftp_get($ftp_connection, $local_file,
$server_file, FTP_BINARY)) {
echo "<br>Successfully downloaded from"
. " $server_file to $local_file.";
}
else {
echo "<br>Error while downloading from"
. " $server_file to $local_file.";
}
}
else {
echo "<br>login failed!";
}
// echo ftp_get_option($ftp_connection, 1);
// Closeing connection
if(ftp_close($ftp_connection)) {
echo "<br>Connection closed Successfully!";
}
}
?>