我正在编写一个从ftp服务器下载文件的应用程序。代码退出时出现错误 - UnknownHostException。该网站有效,我已在filezilla中打开它。代码如下 -
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;
}
}
感谢任何帮助。提前谢谢。