I'm developing an Android app to connect to a FTP server and download video files hosted on the FTP server and save to a folder inside the SD card. For that I'm using "org.apache.commons.net.ftp.FTPClient" library. I can connect to the server and get the list of file names on the server from my app, but after I download video files, they get copied to the folder I gave and there size is indicated as 10 bytes and they can't be played(Looks like corrupted). Can some one suggest me a way to over come this issue. The code I used is attached here with.
** Connect to the FTP server**
public FTPClient mFTPClient = null;
public boolean ftpConnect(String host, String username,String password, int port)
{
try {
mFTPClient = new FTPClient();
mFTPClient.connect(host,port);
// now check the reply code, if positive mean connection success
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode()))
{
// login using username & password
boolean status = mFTPClient.login(username, password);
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
return status;
}
}
catch(Exception e)
{
System.out.println("Error: could not connect to host " + host);
e.printStackTrace();
}
return false;
}
Download files
public boolean ftpDownload(String srcFilePath, String desFilePath)
{
boolean status = false;
try {
FileOutputStream desFileStream = new FileOutputStream(desFilePath);
status = mFTPClient.retrieveFile(srcFilePath, desFileStream);
desFileStream.close();
return status;
} catch (Exception e) {
System.out.println( "download failed");
e.printStackTrace();
}
return status;
}