[英]ftp_get(): Transfer failed
This is the code that I am using 这是我正在使用的代码
<?php
// connect and login to FTP server
$ftp_server = "ftp_server";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
ftp_pasv($ftp_conn, TRUE);
ftp_set_option($ftp_conn, FTP_TIMEOUT_SEC, 2800);
$ftp_username="ftp_username";
$ftp_userpass="ftp_userpass";
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$local_file = "local_file";
$server_file = "server_file";
if (ftp_get($ftp_conn, $local_file, $server_file, FTP_BINARY))
{
echo "Successfully written to ".$local_file;
}
else
{
echo "Error downloading ".$server_file;
}
// close connection
ftp_close($ftp_conn);
I get the same error all the time- 我一直都遇到相同的错误-
"Warning: ftp_get(): Transfer failed in myfile.php on line 33 Error downloading server_file" “警告:ftp_get():在第33行的myfile.php中传输失败,下载server_file时出错”
I try to see if the file that I am trying to get is the right one so I used this code- 我尝试查看我要获取的文件是否正确,因此我使用了以下代码:
$res = ftp_size($ftp_conn, $server_file);
if ($res != -1) {
echo "size of $server_file is $res bytes";
} else {
echo "couldn't get the size";
}
I get the file size so the file is exist. 我得到了文件大小,因此该文件存在。 The file is about 11MB so the size of the file not suppose to be an issue.
该文件约为11MB,因此该文件的大小不应该是一个问题。
I added the lines : 我添加了以下行:
ftp_pasv($ftp_conn, TRUE);
ftp_set_option($ftp_conn, FTP_TIMEOUT_SEC, 2800);
After searching solutions on the web but the results are the same with or without those lines... 在网上搜索解决方案后,无论有无这些行,结果都是相同的...
Any ideas? 有任何想法吗?
Cheerz 切尔兹
You need to call ftp_pasv()
after ftp_login()
, not before. 您需要在
ftp_login()
之后而不是之前调用ftp_pasv()
。 Check the return value of the function call to see if it succeeds. 检查函数调用的返回值以查看是否成功。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.