我正在尝试使用 php 将文件上传到 ftp。服务器管理员的唯一要求是加密应该是Require explicit FTP over TLS
. 就是这样,但我遇到了错误Warning: ftp_fput() [function.ftp-fput]: Can't open data connection.
。我设法连接(在被动模式下),但它无法使用任何功能(、、、ftp_put
)ftp_nb_put
上传ftp_fput
。错误总是一样的。我正在尝试以下代码:
$host = 'ftps.someserver.net';
$user = '****';
$pass = '****';
$filename = "somefile.txt"
$dest_file = $filename;
$source_file = dirname(__FILE__) . '/' . $filename;
$fp = fopen($source_file, 'r');
$ftp = ftp_ssl_connect($host, 21, 180);
if (ftp_login($ftp,$user,$pass)) {
var_dump(ftp_pasv($ftp, true)); // gives me true
// # first way
// ftp_put($ftp, $dest_file, $source_file, FTP_BINARY);
// # second
// $ret = ftp_nb_put($ftp, $dest_file, $source_file, FTP_BINARY, FTP_AUTORESUME);
// while (FTP_MOREDATA == $ret)
// {
// $ret = ftp_nb_continue($ftp);
// }
// # third
if (ftp_fput($ftp, $dest_file, $fp, FTP_ASCII)) { // I was trying FTP_BINARY and FTP_ASCII.
echo "Successfully uploaded\n";
} else {
echo "There was a problem while uploading\n";
}
}
ftp_close($ftp);
fclose($fp);
它适用于我自己的 ftp,它不要求显式 TLS。任何想法,将不胜感激。