我正在制作一个使用apache commons net API的FTPCLient类连接到FTP Server的程序。这是代码:

    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);

       }

.....
我在连接line()处收到异常。
org.apache.commons.net.MalformedServerReplyException: Could not parse response code.

最佳答案

试试这个

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

注意:端口22用于SSH,sftp不用于ftp

如果是sftp,则需要使用commons-vfs

07-24 09:47
查看更多