我通过ftp为上传文件编写了这段代码。
<?php
$file = 'index.php';
$fp = fopen($file, 'r');
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// Initate the upload
$ret = ftp_nb_fput($conn_id, $file, $fp, FTP_BINARY);
while ($ret == FTP_MOREDATA) {
// Do whatever you want
echo ".";
// Continue upload...
$ret = ftp_nb_continue($conn_id);
}
if ($ret != FTP_FINISHED) {
echo "There was an error uploading the file...";
exit(1);
}
fclose($fp);
?>
我收到此错误: 警告:ftp_nb_fput():无法打开到端口2804的数据连接:连接被拒绝 我禁用防火墙但不起作用!
答案 0 :(得分:0)
尝试在pasv模式下运行,ftp_pasv($ conn_id,true);完成后请使用ftp_close($ conn_id)。
谢谢Ohgodwhy!