java - 0 bytes file download with Apache Commons FTPSClient -


using apache commons ftpsclient downloaded file stored 0 bytes. tried different methods, 0 bytes on stored file. on code below show 3 methods.

here used code:

public static void main(string[] args) { string server = "ftps-url"; int port = 6321; string user = ""; string pass = "";  ftpsclient ftp = null; try {     ftp = new ftpsclient("ssl");     ftp.setauthvalue("ssl");     ftp.addprotocolcommandlistener(new printcommandlistener(new printwriter(system.out)));      int reply;      ftp.connect(server, port);     system.out.println("connecting");     system.out.print(ftp.getreplystring());      // after connection attempt, should check reply code verify success.     reply = ftp.getreplycode();      if (!ftpreply.ispositivecompletion(reply)) {         ftp.disconnect();         system.err.println("ftp server refused connection.");         system.exit(1);     }     ftp.login(user, pass);      ftp.execpbsz(0);     ftp.execprot("p");      // ... // transfer files     ftp.setbuffersize(1000);     ftp.enterlocalpassivemode();     // ftp.setcontrolencoding("gb2312");     ftp.changeworkingdirectory("/output"); //path files     ftp.setfiletype(ftp.binary_file_type);     //system.out.println("remote system " + ftp.getsystemname());      string[] filelist = ftp.listnames();  //returns null     system.out.println(filelist.length);     system.out.println(arrays.tostring(filelist));      // method 1     file infile = new file("myfile.xls");     if (!infile.exists()) {                        infile.createnewfile();     }     inputstream input = new fileinputstream(infile);     ftp.completependingcommand();     ftp.storefile(filelist[0], input);     input.close();      // method 2     fileoutputstream fos = new fileoutputstream("myfile.xls");     ftp.retrievefile(filelist[0], fos);     fos.flush();     fos.close();      //ftp.completependingcommand();      // method 3     file path = new file("c:/users/user/desktop/");     string remotefilepath = "/output/" + filelist[0];     file resultfile = new file(path, filelist[0]);     checkedoutputstream fout = new checkedoutputstream(new fileoutputstream(resultfile), new crc32());     ftp.retrievefile(remotefilepath, fout);     } catch (exception ex) {         system.out.println("error");         ex.printstacktrace();     } {         // logs out , disconnects server         try {             if (ftp.isconnected()) {                 ftp.logout();                 ftp.disconnect();             }         } catch (exception ex) {             ex.printstacktrace();         }     } } 

method 1 upload, not download, , clobbers file @ server 0 length file, methods 2 , 3 both correctly retrieve 0 length file.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -