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 経由でサーバーに接続することもできます。
助けてください、私はこれで立ち往生しています。
ありがとう