FTPClient 在 Android 上上传到 ftp 服务器时损坏图像?
我正在尝试从 Android 手机 (HTC Desire HD) 将图像上传到 FTP 服务器(在我的本地 PC 上)。图像将发送到 FTP 服务器,但它们已损坏。
方法 (ftpClient.storeFile()) 抛出 IOException(错误文件号)
请帮助我。
这是损坏的图像链接:
http://imageshack.us/photo/my -images/820/komikb.jpg/
这是代码:
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect("192.168.2.14");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftpClient.setSoTimeout(10000);
ftpClient.enterLocalPassiveMode();
if(ftpClient.login("Administrator", "xxxx"))
{
File sFile=new File("mnt/sdcard/DCIM/komik.jpg");
FileInputStream fs= new FileInputStream(sFile);
String fileName = sFile.getName();
Boolean result = ftpClient.storeFile("/ftpfile.atspace.co.uk/" + fileName, fs);
String has = "";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I'm trying to upload images to a FTP server (on my local PC) from Android Phone (HTC Desire HD). Images are going to FTP server but they are corrupted.
And the method (ftpClient.storeFile()) throws IOException (Bad File Number)
Please help me.
This is the corrupted image link:
http://imageshack.us/photo/my-images/820/komikb.jpg/
And this is the code:
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect("192.168.2.14");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftpClient.setSoTimeout(10000);
ftpClient.enterLocalPassiveMode();
if(ftpClient.login("Administrator", "xxxx"))
{
File sFile=new File("mnt/sdcard/DCIM/komik.jpg");
FileInputStream fs= new FileInputStream(sFile);
String fileName = sFile.getName();
Boolean result = ftpClient.storeFile("/ftpfile.atspace.co.uk/" + fileName, fs);
String has = "";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apache FTP 客户端在这方面有几个突出的问题。下面是有关如何使用 Ftp4J 通过 java 以编程方式有效处理 ftp 的说明。
下载 Ftp4J: http://www.sauronsoftware.it/projects/ftp4j/download.php< /a>
然后在你的 IDE 中:
Apache FTP Client has several outstanding issues with this. Below are instructions on how to use Ftp4J to effectively handle ftp programatically though java.
Download Ftp4J: http://www.sauronsoftware.it/projects/ftp4j/download.php
Then in your IDE:
问题解决了。 FTPClient 类存在“最后一个数据包数据丢失错误”。但这在 3.0.1 23.05.2011 版本中得到了解决。
关于bug的详细解释可以看到:
https://issues.apache.org/jira/browse/NET-409
您可以下载固定版本
https://repository.apache。 org/content/repositories/snapshots/commons-net/commons-net/3.0.1-SNAPSHOT/
Problem is solved. FTPClient class has "last packet data loss bug". But this was solved with 3.0.1 23.05.2011 release.
You can see from detailed explanation about bug:
https://issues.apache.org/jira/browse/NET-409
You can download fixed relea
https://repository.apache.org/content/repositories/snapshots/commons-net/commons-net/3.0.1-SNAPSHOT/