【发布时间】:2021-06-25 08:05:33
【问题描述】:
我正在尝试使用此脚本从 FTP 源下载 zip 文件(在 localhost 上它可以工作,但在实时服务器表单 OVH 上却不行)。
在实时服务器上运行它时,我会立即得到:
- 成功连接到ftp服务器!
- 登录成功!
- 从...下载时出错。
- 连接成功关闭!
所以所有连接都很好,但下载文件时卡住了。
可能是什么问题,或者我如何获得一些错误报告?
有些人认为我已经检查过:
- 已启用 FTP 支持(在 PHP 中)
- 文件夹的权限为 777;
- 端口已打开 (21);
- php max execution is long (300);
- 主机提供的防火墙被禁用(我无法控制是否只是开/关)
还能是什么?
谢谢
// 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!";
}
}
?>
【问题讨论】: