次のコードは、ファイルを取得し(どのファイルでもいいのですが、今はとにかく画像を使用しています)、サーバーにアップロードすることを目的としています(これは機能します、何とか何とか何とか)。唯一の問題は、転送後に画像がかなり歪んでいることです。主な提案は、FTPClientのsetFileTranferModeをFTPClient.BINARY_FILE_TYPEに使用することです。これは、この時点では効果がありません。
メソッドのコードは次のとおりです。
public void sendFile(File sendMe) throws IOException{
f.connect(ip);
f.login(username, password);
String recipient=null;
while(!f.changeWorkingDirectory(path+recipient)){
recipient=JOptionPane.showInputDialog("What is the name of the computer you are sending this to?");
}
f.changeWorkingDirectory(path+recipient);
f.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
f.storeFile(sendMe.getName(), new BufferedInputStream(new FileInputStream(sendMe)));
System.out.println("Stored!");
f.disconnect();
System.out.println("Uploaded");
}
いつものように、どんな助けでも大歓迎です!ありがとう!