0
代碼:文件沒有從ftp下載
import java.io.FileOutputStream; import org.apache.commons.net.ftp.FTPClient;
public class FtpDownloader {
// Server Credentials
String host = "ip";
String username = "user";
String password = "pass";
public static void main(String args[]) {
new FtpDownloader().downloadFile();
}
public void downloadFile() {
try {
FTPClient client_ftp = new FTPClient();
FileOutputStream fos = null;
client_ftp.connect(host);
client_ftp.login(username, password);
System.out.println("Connected : " + client_ftp.isConnected());
fos = new FileOutputStream("d://update_mac.txt");
Boolean file_got = client_ftp.retrieveFile("/update/update_mac.txt", fos);
System.out.println("Downloaded : " + file_got);
fos.close();
client_ftp.disconnect();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
正如你可以看到我試圖下載從FTP服務器上的文件,但是當我運行建立連接的代碼,但該文件沒有得到下載它顯示我的system.What 0KB您認爲原因可能是?
在此先感謝
我也試過這個http://www.javabeat.net/tips/36-file-upload-and-download-using-java.html方法,但它給了我畸形的url異常,但是當我把在我的瀏覽器中的相同網址它給我的文件。 – Jinith 2011-03-05 14:08:29
'FTPClient'不是標準Java API的一部分,但是這個可以從Apache Commons Net中識別出來。在將來的問題中,請明確提及第三方庫。 – BalusC 2011-03-05 14:29:54
org.apache.commons.net.ftp.FTPClient;這是我正在使用的api – Jinith 2011-03-07 11:39:03