Burchi created FTPSERVER-501:
--------------------------------
Summary: java.net.SocketException: Socket closed
Key: FTPSERVER-501
URL: https://issues.apache.org/jira/browse/FTPSERVER-501
Project: FtpServer
Issue Type: Bug
Reporter: Burchi
Using apache FtpServer to create an internal FTP server in Java, i received
some errors. So, i am running a file upload on FTP from 4-5 threads in parallel
and from time to time the upload is failing. The behaviour is not always the
same, i mean out of 10 successive runs 8 times it works properly.
The error stack trace is:
java.net.SocketException:
{code:java}
Socket closed
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:403)
at
java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:609)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:188)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:209){code}
The source code generating the error above:
{code:java}
public ReturnStatus sendFile(String remoteFilename, InputStream input, String
hostname, String username, String password, Integer port) {
ReturnStatus ftpCreatedStatus = createAndConnectFtp(hostname, port);
if (ftpCreatedStatus != ReturnStatus.Successful) {
return ftpCreatedStatus;
}
try {
LoggingUtils.error(this, "Trying to login to " + hostname);
if (!ftp.login(username, password)) {
return ReturnStatus.FailedLogin;
}
logger.info("Remote server address is " + hostname);
logger.info("Remote system is " + ftp.getSystemType());
ftp.setFileType(FTP.BINARY_FILE_TYPE);
// Use passive mode as default because most of us are behind fire walls these
days
ftp.enterLocalPassiveMode();
if (!ftp.storeFile(remoteFilename, input)) {
throw new RuntimeException(ftp.getReplyString());
}
ftp.logout();
} catch (FTPConnectionClosedException e) {
logger.log(Level.WARNING, e.getMessage(), e);
ReturnStatus.ServerClosedConnection.setErrorDesc(e.getMessage());
return ReturnStatus.ServerClosedConnection;
} catch (FileNotFoundException e) {
logger.log(Level.WARNING, e.getMessage(), e);
ReturnStatus.FileNotFound.setErrorDesc("File Not Found");
return ReturnStatus.FileNotFound;
} catch (IOException e) {
logger.log(Level.WARNING, e.getMessage(), e);
ReturnStatus.UnknownError.setErrorDesc(e.getMessage());
return ReturnStatus.UnknownError;
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
// do nothing
}
}
}
return ReturnStatus.Successful;
}{code}
So, it seems that when i am trying to login, the connection is closed even if
i I opened the connection before. The line generating the error is:
{code:java}
if (!ftp.login(username, password)){code}
Worth to mention: running sequentially do not encounter any problems
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]