40

次のコードの何が問題なのか、誰か説明してもらえますか? 別のホスト、FTPClientConfigs を試してみましたが、firefox/filezilla から適切にアクセスできます...問題は、例外なく常に空のファイルリストを取得することです (files.length == 0)。Maven と共にインストールされた commons-net-2.1.jar を使用します。

    FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_L8);

    FTPClient client = new FTPClient();
    client.configure(config);

    client.connect("c64.rulez.org");
    client.login("anonymous", "anonymous");
    client.enterRemotePassiveMode();

    FTPFile[] files = client.listFiles();
    Assert.assertTrue(files.length > 0);
4

4 に答える 4

101

それを見つけた!

問題は、接続後、ログインする前にパッシブモードに入りたいということです。あなたのコードは私には何も返しませんが、これは私にとってはうまくいきます:

import org.apache.commons.net.ftp.FTPClient;
import java.io.IOException;
import org.apache.commons.net.ftp.FTPFile;

public class BasicFTP {

    public static void main(String[] args) throws IOException {
        FTPClient client = new FTPClient();
        client.connect("c64.rulez.org");
        client.enterLocalPassiveMode();
        client.login("anonymous", "");
        FTPFile[] files = client.listFiles("/pub");
        for (FTPFile file : files) {
            System.out.println(file.getName());
        }
    }
}

この出力が得られます:

c128
c64
c64.hu
着信
プラス4
于 2011-03-03T16:06:18.117 に答える
3

通常、匿名ユーザーはパスワードを必要としません。

client.login("anonymous", "");
于 2010-08-13T19:18:47.520 に答える