2013-08-02 36 views
0

我必須通過ftp連接到一臺服務器並下載一個zip文件。通過ftp與PHP連接

這是我曾嘗試沒有任何的運氣:

$url = $server_file = '/expiring_service_auctions.csv.zip'; 
$target = $local_file = 'godaddy.zip'; 
$out = 'godaddy.csv'; 


$ftp_server = 'ftp.godaddy.com'; //'208.109.78.100' 
$ftp_user_name = 'auctions'; 
$ftp_user_pass = ''; //no pass 


// set up basic connection 
$conn_id = ftp_connect($ftp_server); 

// login with username and password 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// get contents of the current directory 
$contents = ftp_nlist($conn_id, "."); 

// output $contents 
var_dump($contents); 

try to download $server_file and save to $local_file 
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) { 
    echo "Successfully written to $local_file\n"; 
} else { 
    echo "There was a problem\n"; 
} 

// close the connection 
ftp_close($conn_id); 

怎麼辦?該怎麼辦?

+0

您是否收到任何錯誤消息? –

+1

不知何故,我懷疑godaddy是否會讓這個文件在他們的文件系統的根。你確定你已經有了正確的源文件路徑嗎?這可能不僅僅是'/ expiring.csv.zip',而更像'/ home/username/expiring.csv.zip'。 –

+0

@MarcB直接登錄到他們的FTP,它在根目錄中。可能是因爲「拍賣」用戶名。 – aynber

回答

2

當我登錄到FTP服務器時,它建議使用PASV。在您的登錄行後添加以下內容:

ftp_pasv($conn_id, true); 
+0

它就像一個魅力,非常感謝你的建議。 –