3
我想寫一個小型的php函數,將文件上傳到FTP服務器,我不斷收到相同的錯誤,但我找不到任何修復方法,我希望你們能幫助我這裏...php ftp上傳問題
我得到的錯誤是:警告:ftp_put()[function.ftp-put]:無法建立數據連接:沒有路由到主機。
該文件是在FTP服務器上創建的,但它是零字節。
下面是代碼:
<?php
$file = "test.dat";
$ftp_server="ftp.server.com";
$ftp_user = "myname";
$ftp_pass = "mypass";
$destination_file = "test.dat";
$cid=ftp_connect($ftp_server);
if(!$cid) {
exit("Could not connect to server: $ftp_server\n");
}
$login_result = ftp_login($cid, $ftp_user, $ftp_pass);
if (!$login_result) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user";
}
$upload = ftp_put($cid, $destination_file, $file, FTP_BINARY);
if (!$upload) {
echo "Failed upload for $source_file to $ftp_server as $destination_file<br>";
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
ftp_close($cid);
?>