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();
}
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/
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: