2010-10-05 133 views
0

我正在IIS 7.5上開發PHP應用程序,該應用程序使用PHP FTP命令。CMD提示> FTP大小命令

ftp_size()之外,這些工作都是有效的。

我測試過:

cmd.exe > ftp host > username > password > SIZE filename = Invalid Command

然而,如果我通過Internet瀏覽器訪問FTP站點時,會顯示文件大小。

我是否需要安裝FTP擴展,如果是的話,哪些和哪些地方可以得到它們?

這裏是PHP代碼:

<?php 
// FTP Credentials 
$ftpServer = "www.domain.com"; 
$ftpUser = "username"; 
$ftpPass = "password"; 

// Unlimited Time 
set_time_limit(0); 

// Connect to FTP Server 
$conn = @ftp_connect($ftpServer) 
or die("Couldn't connect to FTP server"); 

// Login to FTP Site 
$login = @ftp_login($conn, $ftpUser, $ftpPass) 
or die("Login credentials were rejected"); 

// Set FTP Passive Mode = True 
ftp_pasv ($conn, true); 

// Build the file list 
$ftp_nlist = ftp_nlist($conn, "."); 

// Alphabetical sorting 
sort($ftp_nlist); 

// Display Output 
foreach ($ftp_nlist as $raw_file) { 
    // Get the last modified time 
    $mod = ftp_mdtm($conn, $raw_file); 
    // Get the file size 
    $size = ftp_size($conn, $raw_file); 
    // Size is not '-1' => file 
     if (!(ftp_size($conn, $raw_file) == -1)) { 
     //output as file 
     echo "Filename: $raw_file<br />"; 
     echo "FileSize: ".number_format($size, '')."Kb</br>"; 
     echo "Last Modified: ".date("d/m/Y H:i", $mod)."</br>"; 
     } 
} 
?> 
+0

你的意思是'ftp_size()'不起作用嗎? http://www.php.net/manual/en/function.ftp-size.php它返回什麼? – 2010-10-05 12:26:33

+0

哦。 。 .yeah,在那裏有錯字,是的,它應該是ftp_size()。它不會返回任何東西,只是顯示大小的空白區域 – 2010-10-05 12:44:56

+0

您可以粘貼您的代碼嗎? – Kev 2010-10-05 16:42:27

回答

0

我只是跑你的代碼對我們的FTP服務器之一,它工作得很好。畢竟,您正在測試的FTP服務器很可能實際上並不支持SIZE命令。

您的網絡瀏覽器工作的原因,我用火狐瀏覽器和Internet Explorer的數據包嗅探器進行了檢查,是因爲他們發出LIST命令並解析結果。