J3R*_*3RN 3 java ftp ftp-client file transfer
下面的代码旨在获取一个文件(任何文件都不错,但现在无论如何我都只是使用图像),然后将其上传到我的服务器上(有效,等等)。唯一的问题是图像在传输后非常歪斜。主要建议是使用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");
}
Run Code Online (Sandbox Code Playgroud)
一如既往,任何帮助将不胜感激!谢谢!
您没有使用正确的方法来设置文件类型。您应该改用setFileType。
f.setFileType(FTPClient.BINARY_FILE_TYPE);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2854 次 |
| 最近记录: |