FTPClient的setFileTransferMode不生效
以下代码旨在获取一个文件(任何文件都可以,但现在我只是使用图像),并将其上传到我的服务器(可以工作,等等)。唯一的问题是传输后图片相当倾斜。主要建议是使用 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");
}
一如既往,任何帮助将不胜感激!谢谢!
The following code is meant to take a file (any file would be nice, but right now I'm just using images anyway), and upload it to my server (which works, blah blah blah). The only problem is that the picture is quite skewed after transfer. The main suggestion is to use FTPClient's setFileTranferMode to FTPClient.BINARY_FILE_TYPE, which... has no effect at this point...
Here's the code for the method:
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");
}
As always, any help would be much appreciated! Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有使用正确的方法来设置文件类型。您应该使用 setFileType< /a> 相反。
You are not using the correct method to set the file type. You should use setFileType instead.
您为什么不用 VB.NET 或 C# 构建自己的 FTP 客户端,而不是依赖第 3 方 FTP 客户端。这样,如果出现问题,您将拥有更多控制权。这是实现这一点的代码:
http://dot-net-talk.blogspot.com/2008/12/how-to-create-ftp-client-in-vbnet.html
Instead of relying on 3rd party FTP clients, why don't you build your own in VB.NET or C#. This way you will have more control if something goes wrong. Here is the code to to just that:
http://dot-net-talk.blogspot.com/2008/12/how-to-create-ftp-client-in-vbnet.html