0

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.

enter image description here 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

PPD
  • 5,660
  • 12
  • 52
  • 86
  • 3
    `con.connect("ftp://speedtest.tele2.net");`. That should be without protocol: `con.connect("speedtest.tele2.net");`. – greenapps Jul 11 '18 at 10:21
  • @greenapps Thanks after removing protocol I am able to connect to server. Let me check whether file is uploaded or not? Thanks for quick response – PPD Jul 11 '18 at 10:26

0 Answers0