I am writing an application to download files from ftp server. The code exits with error - UnknownHostException. The site is valid and I have opened it in filezilla. The code follows -
public class Downloader extends AsyncTask<String, Integer, String> {
private FTPClient mFtp;
private FTPFile[] files;
public Downloader() {
mFtp=new FTPClient();
try {
mFtp.connect(InetAddress.getByName("fenils.in"));
// mFtp.connect("ftp://fenils.in");
mFtp.login("*****", "******");
mFtp.setFileType(FTP.BINARY_FILE_TYPE);
mFtp.enterLocalPassiveMode();
files=mFtp.listFiles("/pankaj/beta");
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected String doInBackground(String... arg0) {
FileOutputStream fos = null;
try {
for(FTPFile f:files){
fos=new FileOutputStream("alpha/"+f.getName());
mFtp.retrieveFile(f.getName(), fos);
}
fos.close();
mFtp.logout();
mFtp.disconnect();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
Any help is appreciated. Thanks in advance.
Sorry. My mistake. I neglected to set the uses internet permission. I found the answer here Java ftpclient application doesn't connect