asynchronous - Android: FTP client file transfer in passive mode taking time to close connection after 100% upload -


android: ftp client file transfer in passive mode taking time close connection after 100% upload

while transferring files through ftp client, in passive mode, using async task. after progress update specified 100% of file has been uploaded, still ftp connection holds async task coming on post execute.

the time taken directly proportional internet speed , size of file uploaded.

tried standalone application upload zip files, tried ftp both in active , passive modes.

still issue persists.

public class uploadzipfiles extends asynctask<object, integer, object> {         arraylist<string> zipfiles;         string username, password;         weakreference<servicestatuslistener> listenerreference;         private context mcontext;         private long totalfilesize = 0;         protected long totaltransferedbytes = 0;         final numberformat nf = numberformat.getinstance();         private customftpclient ftpclient = null;          public uploadzipfiles(context mcontext, servicestatuslistener listener,                 arraylist<string> zipfiles, string username, string password) {             log.d("u , p", "" + username + "=" + password);             this.mcontext = mcontext;             this.zipfiles = zipfiles;             this.username = username;             this.password = password;             this.listenerreference = new weakreference<servicestatuslistener>(                     listener);             nf.setminimumfractiondigits(2);             nf.setmaximumfractiondigits(2);          }          @override         protected void onpreexecute() {             super.onpreexecute();             // getting total size of file             (string file : zipfiles) {                  totalfilesize = totalfilesize + new file(file).length();             }         }          @override         protected object doinbackground(object... arg0) {              ftpclient = new customftpclient();              try {                 ftpclient.connect(ftpurl, 21);                  ftpclient.login(username, password);                  ftpclient.setfiletype(ftpclient.binary_file_type);                  (string file : zipfiles) {                      inputstream in;                      in = new fileinputstream(new file(file));                      ftpclient.storefile(new file(file).getname(), in);                      in.close();                  }               } catch (ioexception e1) {                 e1.printstacktrace();             }              return "success";         }          @override         protected void onpostexecute(object result) {              if (result instanceof exception) {                 listenerreference.get().onfailure(                         new exception(result.tostring()));             } else {                 listenerreference.get().onsuccess("success");             }           }          @override         protected void onprogressupdate(integer... values) {              int uploadprogress = ((float) values[0] / totalfilesize) * 100);             //some code show loader             .......           }          /** custom client publish progress **/          public class customftpclient extends ftpclient {              public boolean storefile(string remote, inputstream local)                     throws ioexception {                 final outputstream output;                 final socket socket;                  if ((socket = _opendataconnection_(ftpcommand.stor, remote)) == null)                     return false;                  output = new bufferedoutputstream(socket.getoutputstream(),                         getbuffersize());                  try {                     util.copystream(local, output, getbuffersize(),                             copystreamevent.unknown_stream_size,                             new copystreamlistener() {                                 @override                                 public void bytestransferred(                                         long totalbytestransferred,                                         int bytestransferred, long streamsize) {                                     totaltransferedbytes = totaltransferedbytes                                             + bytestransferred;                                     publishprogress((int) totaltransferedbytes);                                      if (totaltransferedbytes == totalfilesize) {                                          log.d(tag, "upload completed");                                      }                                  }                                  @override                                 public void bytestransferred(                                         copystreamevent arg0) {                                     // todo auto-generated method stub                                  }                             });                   } catch (ioexception e) {                     try {                         socket.close();                     } catch (ioexception f) {                     }                     throw e;                    }                 output.close();                 socket.close();                 return completependingcommand();             }         }     } 


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -