4

Java コードを介してクライアントの ftps サーバーに接続しようとしています。そのためにApache Commonsライブラリを使用しています。しかし、私はそうすることができません。誰でもこれで私を助けてくれませんか。

クライアント サーバーは FTPS/暗黙的 SSL 接続を使用し、データ接続にはパッシブ モードを使用します。

私のコードは次のとおりです。

public static void connectServer(String host, int port, String userName, String password) throws Exception {
    FTPSClient client = new FTPSClient("SSL", true);
    String remote = "Contact.xml";

    File inFile = new File("C:/Documents/Applications/Contact.xml");
    File outFile = new File("C:/Documents/Applications/Sample.xml");

    InputStream input = new FileInputStream(inFile);
    InputStream out = new FileInputStream(outFile);

    try {

        if(client.isConnected()){
            client.disconnect();
        }

        client.connect(host,990);
        client.enterLocalPassiveMode();
        client.enterRemotePassiveMode();

        client.login(userName, password);

        client.setBufferSize((int)inFile.length()+100);
        client.completePendingCommand();

        System.out.println(client.printWorkingDirectory());
        System.out.println(inFile.getAbsolutePath());

        client.storeFile(remote, input);
        out = client.retrieveFileStream("/folder/inputfeed.xml");

        client.completePendingCommand();
        client.logout();

    } catch (Exception e) {
    e.printStackTrace();
        System.err.println(client.getReplyString());

    } finally {
        out.close();
        input.close();
        client.disconnect();
    }
}

このコードは例外をスローしませんが、ファイルがサーバーにコピーされていることも、データが InputStream にコピーされていることもわかりません。また、作業ディレクトリを取得するための sysout ステートメントは、正しいディレクトリを返します。Filezilla と WinSCP 経由でサーバーに接続することもできます。

助けてください、私はこれで立ち往生しています。

ありがとう

4

5 に答える 5

0

login() の前にパッシブ モードに入るのはなぜですか?

症状はアクティブ モードの症状であり、FW ルール DROP が原因で接続を確立できないためです (REJECT ではありません。拒否するとすぐに例外がスローされますが、DROP は永久にハングする可能性があります)。

PSまた、「リモート」パッシブモードとは何かが明確ではありません。唯一の違いは「ローカル」です。

于 2011-04-28T21:22:50.427 に答える
0

enterRemotePassiveMode();クライアントからサーバーではなく、サーバーからサーバーへの接続にのみ使用されます。その行を削除します。

于 2012-10-07T23:36:31.537 に答える