我試圖用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
)。錯誤總是一樣的。我試着下面的代碼:要求使用PHP通過TLS進行明確的FTP
$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。任何想法,將不勝感激。
您是否已經在服務器上設置了您的TLS證書? –
它是共享主機,但它已經安裝了SSL證書。 –