2011-01-21 194 views
3

我正在製作一個程序,使用apache commons net API的FTPCLient類連接到FTP Server。這裏是代碼:Apache Commons Net API的使用

FTPClient client = new FTPClient(); 
    byte[] b = new byte[4]; 
    b[ 0] = new Integer(127).byteValue(); 
    b[ 1] = new Integer(0).byteValue(); 
    b[ 2] = new Integer(0).byteValue(); 
    b[ 3] = new Integer(1).byteValue(); 
    try{ 

      InetAddress address = InetAddress.getByAddress(b); 
     client.connect(address,22); 

     } 

..... 我會在連接線()除外。

org.apache.commons.net.MalformedServerReplyException: Could not parse response code. 

回答

2

嘗試用這種

FTPClient f = new FTPClient(); 
f.connect(server); 
f.login(username, password); 
FTPFile[] files = listFiles(directory); 

注:端口22用於SSH,SFTP不是FTP

如果SFTP,那麼你需要去commons-vfs

相關問題