Error while trying to download a file via ftp on android -


i amateur in android coding. trying setup android app ability download file ftp server. while running code on android 2.2 emulator, able connect ftp server downloading part showing error. logcat gives "download failed".

package com.ftconnect.down; import java.io.fileoutputstream; import android.app.activity; import android.os.bundle; import android.util.log; import org.apache.commons.net.ftp.*;  public class ftpconnectactivity extends activity { /** called when activity first created. */  public ftpclient mftpclient = null; public boolean mconnect; public boolean mdownload; public boolean mdisconnected;  public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      mconnect = ftpconnect("xxx.xxx.xxx.xxx", "admin",             "123456", 21);      mdownload = ftpdownload("xxx.xxx.xxx.xxx/ftp.mp3", "/sdcard");      mdisconnected = ftpdisconnect();  }  public boolean ftpconnect(string host, string username, string password,         int port) {     try {         mftpclient = new ftpclient();         // connecting host         mftpclient.connect(host, port);         log.d("ftpconnectapp", "connecting " + host);          // check reply code, if positive mean connection success         if (ftpreply.ispositivecompletion(mftpclient.getreplycode())) {             // login using username & password             boolean status = mftpclient.login(username, password);             return status;         }     } catch (exception e) {         log.d("ftpconnectapp", "error: not connect host " + host);     }      return false; }  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) {         log.d("ftpconnectapp", "download failed");     }      return status; }  public boolean ftpdisconnect() {     try {         mftpclient.logout();         mftpclient.disconnect();         return true;     } catch (exception e) {         log.d("ftpconnectapp",                 "error occurred while disconnecting ftp server.");     }      return false; }  } 

i have setup internet , write external permission in android manifest file. should include other permissions?

also, let me know if there changes made code above. destination address '/sdcard' correct?

thanks in advance.

you need add exception variable in log message. may want print full stack trace of problem using: e.printstacktrace(); /sdcard should work, more reliable request sd card location using environment object. see more details file storage on android in link


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -