I want to upload apk file to FTP server. For this currently I am using public FTP server. I had tried to upload file to server using FileZilla and WinSCP and I had uploaded file successfully using these tools.
here in image I had connected to this FTP server
But same when I tried to using programmatically I am getting exception
Following is my code:
public void uploadApkToFtp(File file, String appName){
FTPClient con = null;
try
{
con = new FTPClient();
con.connect("ftp://speedtest.tele2.net");
if (con.login("anonymous", "anonymous")) {
con.enterLocalPassiveMode();
con.setFileType(FTP.BINARY_FILE_TYPE);
FileInputStream in = new FileInputStream(file);
boolean result = con.storeFile("/appName", in);
System.out.println (">>>>>>>>>>result "+result);
in.close();
if (result) Log.v("upload result", "succeeded");
con.logout();
con.disconnect();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
But here I am getting Exception as: java.net.UnknownHostException: ftp://speedtest.tele2.net. Getting UnknownHostException at line con.connect("ftp://speedtest.tele2.net");
Any idea what wrong doing i am in this? Thanks in advance (internet and storage permission are given)
Hi After removing protocol suggested by @greenapps, it works Fine. Thanks