【问题标题】:Apache Commons Net API usageApache Commons Net API 使用
【发布时间】:2011-01-21 06:55:17
【问题描述】:

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

    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.

【问题讨论】:

    标签: java ftp


    【解决方案1】:

    试试这个

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

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

    如果是 sftp,那么你需要去commons-vfs

    【讨论】:

      猜你喜欢
      • 2014-03-26
      • 2023-04-05
      • 2014-12-10
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      • 2023-03-30
      相关资源
      最近更新 更多