1
我可以使用FTP客戶端連接到服務器,並且無需上下移動文件。當我嘗試使用ftp_put時,它無法上傳文件。我正在服務器1上打開一個目錄並讀取文件並刪除任何文件。列表,當文件被讀取時,我在屏幕上顯示文件以查看它們已列出,然後嘗試使用ftp_put將它們上載到服務器2,但它們無法上載。任何人都可以看到爲什麼這不起作用請。在服務器2上的文件夾的權限設置正確,我已連接並嘗試使用pasv模式。無法使用fput將txt文件添加到服務器
$conn_id = ftp_connect($ftp_server,$port);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (!$conn_id) {
echo 'Failed to connect';
} else {
if (!$login_result) {
echo 'Failed to log in';
} else {
ftp_pasv($conn_id, true);
$path='this/path';
$dir_handle = opendir($path) or die("Error opening $path");
while ($file = readdir($dir_handle)) {
if (substr($file,0,1)=='.') {
} else {
$upload = ftp_put($conn_id, 'Testdir/FilesInThisDir/'.$file, $file, FTP_ASCII);
print (!$upload) ? 'Cannot upload '.$file : 'Upload complete';
print "<br>";
}
}
}
}
ftp_close($conn_id);
你能確認'$ conn_id'已被正確初始化嗎?換句話說,你可以閱讀'Testdir /'的內容嗎? – Floris
您好弗洛里斯是的,它是正確的,我可以列出當前內容Testdir/FilesInThisDir/ –
目錄中的Cureent文件是Testdir/FilesInThisDir/test3.txt –