2012-03-22 76 views
1

上傳大文件我試圖使用FTPClient的storeFile(遠程,本地)方法上載一個大文件(大於8 MB),但它會導致false.It獲取上傳與一些額外的字節。以下是代碼與輸出:無法在FTP上使用Apache commons-net-3.1

public class Main { 
public static void main(String[] args) { 
FTPClient client = new FTPClient(); 
FileInputStream fis = null; 

try { 

client.connect("208.106.181.143"); 
client.setFileTransferMode(client.BINARY_FILE_TYPE); 
client.login("abc", "java"); 
int reply = client.getReplyCode(); 
System.out.println("Received Reply from FTP Connection:" + reply); 

if(FTPReply.isPositiveCompletion(reply)){ 
    System.out.println("Connected Success"); 
} 

client.changeWorkingDirectory("/"+"Everbest"+"/"); 
client.makeDirectory("ETPSupplyChain5.3-EvbstSP3"); 
client.changeWorkingDirectory("/"+"Everbest"+"/"+"ETPSupplyChain5.3-EvbstSP3"+"/"); 
FTPFile[] names = client.listFiles(); 
String filename = "E:\\Nitin\\D-Drive\\Installer.rar"; 

fis = new FileInputStream(filename); 

boolean result = client.storeFile("Installer.rar", fis); 
int replyAfterupload = client.getReplyCode(); 
System.out.println("Received Reply from FTP Connection replyAfterupload:" + replyAfterupload); 
System.out.println("result:"+result); 
for (FTPFile name : names) { 
    System.out.println("Name = " + name); 
    } 

client.logout(); 

fis.close(); 



client.disconnect(); 
} catch (SocketException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
} 
} 




o/p: 
Received Reply from FTP Connection:230 
Connected Success 
32 /Everbest/ETPSupplyChain5.3-EvbstSP3 
Received Reply from FTP Connection replyAfterupload:150 
result:false 
+0

嗨,任何人都可以讓我知道,如果FTPClient的storeFile(遠程,本地)方法有FTP上傳文件的任何大小限制。 – Nitin 2012-03-23 03:53:27

回答

0

首先,一個8 MB文件不是一個大文件。我設法使用這個庫上傳大於100Mb的文件。

撥打setFileType方法之前storeFile方法與參數BINARY_FILE_TYPE。它告訴服務器你的文件不應該存儲爲ASCII。

最後,嘗試關閉FileInputStream之後的storeFile方法。並捕獲close方法的結果。

相關問題