2011-01-21 96 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