ftp - FTPSClient file upload and download always size 0 and exception -
installed filezilla server , enabled ftp on tls settings in settings , started server. through eclipse java client tried connect server upload , download file using below code using commons-net apache library.
ftpsclient ftpclient = new ftpsclient(false); // connect host ftpclient.connect(mserver, mport); int reply = ftpclient.getreplycode(); system.out.println("the reply code "+reply); if (ftpreply.ispositivecompletion(reply)) { // login if (ftpclient.login("******", "*******")) { // set protection buffer size ftpclient.execpbsz(0); // set data channel protection private ftpclient.execprot("p"); // enter local passive mode ftpclient.enterlocalpassivemode(); // upload file using storefile file firstlocalfile = new file("e:/test.txt"); string firstremotefile = "hello.txt"; inputstream = new fileinputstream(firstlocalfile); string result = getstringfrominputstream(is); system.out.println(result); object output = ftpclient.storefile(firstremotefile, is); system.out.println(output); is.close(); // download file using retrievefile(string, outputstream) string remotefile1 = "/settings.xml"; file downloadfile1 = new file("e:/testoutput.xml"); outputstream outputstream1 = new bufferedoutputstream(new fileoutputstream(downloadfile1)); boolean success = ftpclient.retrievefile(remotefile1, outputstream1); outputstream1.close(); if (success) { system.out.println("file #1 has been downloaded successfully."); } // logout ftpclient.logout(); // disconnect ftpclient.disconnect(); } else { system.out.println("ftp login failed"); } // disconnect ftpclient.disconnect(); } else { system.out.println("ftp connect host failed"); } } catch (ioexception ioe) { system.out.println("ftp client received network error"); ioe.printstacktrace(); } catch (exception nsae) { system.out.println("ftp client not use ssl algorithm"); nsae.printstacktrace(); }
it creates file hello.txt on server size of 0kb (source file size 10 kb) , ended following error. please me resolve this
javax.net.ssl.sslhandshakeexception: remote host closed connection during handshake @ sun.security.ssl.sslsocketimpl.readrecord(unknown source) @ sun.security.ssl.sslsocketimpl.performinitialhandshake(unknown source) @ sun.security.ssl.sslsocketimpl.starthandshake(unknown source) @ sun.security.ssl.sslsocketimpl.starthandshake(unknown source) @ org.apache.commons.net.ftp.ftpsclient._opendataconnection_(ftpsclient.java:619) @ org.apache.commons.net.ftp.ftpclient._storefile(ftpclient.java:633) @ org.apache.commons.net.ftp.ftpclient.__storefile(ftpclient.java:624) @ org.apache.commons.net.ftp.ftpclient.storefile(ftpclient.java:1976) @ com.test.ftps.testclass.main(testclass.java:88) caused by: java.io.eofexception: ssl peer shut down incorrectly @ sun.security.ssl.inputrecord.read(unknown source) ... 9 more
just un-tick "require tlc session resumption on data connection..." in filezilla server -> settings -> ftp on tls settings -> un-tick require tlc session resumption on data connection when using prot p
Comments
Post a Comment