java - FTPSClient raise an exception when trying to login() after logout() -
I want to write code in Java that connects to the server's list using FTP on the SSL protocol and receives some files from it is. Every server has a log in and a list of passwords. In every login I need to connect to the server in something like this: I am using FTPSClient from Apache Commons: This code fails when I try to logout and log in once in the same connection. I get this exception: but if I close the connection (FtpClient.disconnect ();) after logout and then open it once again (ftpClient.connect ("host", port)) works fine in the code below. This is not the legal client API for issuing any order after a shutdown, And then new login (); You should issue a reinitialize; Otherwise you can try just new login (without first logout), even if the second login is allowed on the same connection, although it is server-based and is not required.
// This is not a real code, this is just what I need to do For the sketch is (server server: server) {server.connect (); (Login password password: server.loginPasswordList) {server.login (login password); Server.getSomeFiles (); Server.logout (); } Server.disconnect (); }
ftpClient = ftpClient.connect ("host", port); Int reply = ftpClient.getReplyCode (); If (FTPReply.isPositiveCompletion (Answer)) {if (ftpClient.login ("Login", "Password")) {ftpClient.execPBSZ (0); FtpClient.execPROT ("P"); FtpClient.enterLocalPassiveMode (); Println (ftpClient.logout ()); // true} if (ftpClient.login ("another_login", "another_password")) {// Exception ftpClient.execPBSZ (0) is generated in this line; FtpClient.execPROT ("P"); FtpClient.enterLocalPassiveMode (); Println (ftpClient.logout ()); // true}}
org.apache.commons.net.ftp.FTPConnectionClosedException: connection closed without signal
ftpClient = ftpClient.connect ("host", port); Int reply = ftpClient.getReplyCode (); If (FTPReply.isPositiveCompletion (Answer)) {if (ftpClient.login ("Login", "Password")) {ftpClient.execPBSZ (0); FtpClient.execPROT ("P"); FtpClient.enterLocalPassiveMode (); Println (ftpClient.logout ()); // true}} ftpClien.disconnect (); FtpClient = ftpClient.connect ("host", port); Int reply = ftpClient.getReplyCode (); If (FTPReply.isPositiveCompletion (Answer)) {if (ftpClient.login ("another_login", "another_password")) {// It works fine ftpClient.execPBSZ (0); FtpClient.execPROT ("P"); FtpClient.enterLocalPassiveMode (); Println (ftpClient.logout ()); Of course I can use this code, but the problem is that there is a large list of servers and logins, and the creation of new connections takes 1 second, but ftpClient .login () only takes ~ 50 ms so if I use every login If I use code with new connection, it will take 3,150 ms on a server for three logins instead of 1150 ms. So what could be the reason why I can not log on to the server after logout?
Comments
Post a Comment