[
https://issues.apache.org/jira/browse/NET-548?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14934639#comment-14934639
]
thompson franklin edited comment on NET-548 at 9/29/15 5:23 AM:
----------------------------------------------------------------
FTPClient Thread hangs for 1 day
Code Hangs at :: boolean fileUploadStatus =
ftpclient.storeFile(remoteDestinationFileName,fis);
Same code works fine in normal cases. Some random time this issue came.
Exception
Trace at : Mon, 28 Sep 15, 21:55:52 PDT
java.net.PlainSocketImpl.socketAccept(Native Method)
java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398)
java.net.ServerSocket.implAccept(ServerSocket.java:530)
java.net.ServerSocket.accept(ServerSocket.java:498)
org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:560)
org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:425)
org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1548)
com.manageengine.eum.ftp.datacollection.FTPDataCollector.doFTPDataCollection(FTPDataCollector.java:1017)
---------------------------
Sample Code
public void doFTPDataCollection()
{
EUMLog.log(module, monitorid+" : FTP DataCollection :
HostName="+hostName+", Port="+portNumber+", TimeOut="+timeOut+",
LocalDest="+localDestinationFileName+",
RemoteSourceFile="+remoteSourceFileName+",
RemoteDest="+remoteDestinationFileName+",
LocalSourceFile="+localSourceFileName+", uploadFileName="+uploadFileName+",
Upload="+uploadEnabled+", Download="+downloadEnabled);
long tempStartTime=0L;
long tempEndTime=0L;
FileOutputStream fos = null;
FileInputStream fis = null;
resolvedIp=java.net.InetAddress.getByName(hostName).getHostAddress();
FTPClient ftpclient = null;
try
{
ftpclient = new FTPClient();
ftpclient.setDefaultTimeout(timeOut*1000);
ftpclient.setConnectTimeout(timeOut*1000);//FTP Set
Timeout
tempStartTime = System.currentTimeMillis();
try
{
ftpclient.connect(hostName,portNumber);//FTP
Connection
ftpclient.setSoTimeout(soTimeOut);//set socket
timeout
isFTPConnected = true;
tempEndTime = System.currentTimeMillis();
connectionTime = tempEndTime - tempStartTime;
}
catch(Exception ex)
{
exceptionErrorMsg = Util.trim(ex.getMessage());
errorcode = Constants.DC_CONNECT_ERR;
}
if(isFTPConnected)
{
EUMLog.log(module, monitorid+" : FTP Connected
Sucessfully : Duration="+connectionTime);
tempStartTime=0L;
tempEndTime=0L;
/*
* FTP Login
*/
tempStartTime = System.currentTimeMillis();
try
{
isLoggedIn =
ftpclient.login(userName,password);
}
catch(Exception ex)
{
exceptionErrorMsg =
Util.trim(ex.getMessage());
errorcode =
Constants.FTP_AUTHENTICATION_FAILED;
EUMLog.log(module, monitorid+" : FTP
Login : Exception : "+exceptionErrorMsg);
if(printlogs)
{
EUMLog.log(module,
Util.getStackTrace(ex));
}
}
tempEndTime = System.currentTimeMillis();
if(isLoggedIn)
{
loginTime = tempEndTime - tempStartTime;
EUMLog.log(module, monitorid+" : FTP
Logged in Sucessfully : Duration="+loginTime);
if(ftpConnectionMode==Constants.FTP_CONNECTION_MODE_PASSIVE)
{
ftpclient.enterLocalPassiveMode();
}
ftpclient.setFileType(FTP.BINARY_FILE_TYPE);
ftpclient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
tempStartTime=0L;
tempEndTime=0L;
/*
* FTP Upload File from Local to Remote
Server
*/
if(uploadEnabled &&
localSourceFileName.length()>0 && remoteDestinationFileName.length()>0)
{
EUMLog.log(module, monitorid+"
: FTP Upload : Starting...");
File localFile = new
File(localSourceFileName);
/*
* Check if the file is present
in the local server
*/
if(localFile.exists())
{
uploadSize =
localFile.length();
uploadSizeInKB =
Util.getSizeInKB(uploadSize);
uploadSizeInMB =
Util.getSizeInMB(uploadSize);
if(isWithinTransferLimit(uploadSize))
{
String sFile[]
= ftpclient.listNames(remoteDestinationFolder);
/*
* Check if the
destination directory is available in the remote server
*/
if(sFile!=null)
{
/*
*
Upload File from local serevr to remote server
*/
tempStartTime = System.currentTimeMillis();
fis =
new FileInputStream(new File(localSourceFileName));
boolean
fileUploadStatus = ftpclient.storeFile(remoteDestinationFileName,fis);
tempEndTime = System.currentTimeMillis();
EUMLog.log(module, monitorid+" : FTP FileUploadStatus="+fileUploadStatus+",
Start="+tempStartTime+", End="+tempEndTime+",
Duration="+(tempEndTime-tempStartTime));
if(fileUploadStatus)
{
uploadTime = tempEndTime - tempStartTime;
if(uploadTime>0)
{
uploadTimeInKBperSec = uploadSizeInKB / ((double)uploadTime/1000.0);
}
}
else
was (Author: thompsonfranklin):
FTPClient Thread hangs for 1 day
Code Hangs at :: boolean fileUploadStatus =
ftpclient.storeFile(remoteDestinationFileName,fis);
Exception
Trace at : Mon, 28 Sep 15, 21:55:52 PDT
java.net.PlainSocketImpl.socketAccept(Native Method)
java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398)
java.net.ServerSocket.implAccept(ServerSocket.java:530)
java.net.ServerSocket.accept(ServerSocket.java:498)
org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:560)
org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:425)
org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1548)
com.manageengine.eum.ftp.datacollection.FTPDataCollector.doFTPDataCollection(FTPDataCollector.java:1017)
---------------------------
Sample Code
public void doFTPDataCollection()
{
EUMLog.log(module, monitorid+" : FTP DataCollection :
HostName="+hostName+", Port="+portNumber+", TimeOut="+timeOut+",
LocalDest="+localDestinationFileName+",
RemoteSourceFile="+remoteSourceFileName+",
RemoteDest="+remoteDestinationFileName+",
LocalSourceFile="+localSourceFileName+", uploadFileName="+uploadFileName+",
Upload="+uploadEnabled+", Download="+downloadEnabled);
long tempStartTime=0L;
long tempEndTime=0L;
FileOutputStream fos = null;
FileInputStream fis = null;
resolvedIp=java.net.InetAddress.getByName(hostName).getHostAddress();
FTPClient ftpclient = null;
try
{
ftpclient = new FTPClient();
ftpclient.setDefaultTimeout(timeOut*1000);
ftpclient.setConnectTimeout(timeOut*1000);//FTP Set
Timeout
tempStartTime = System.currentTimeMillis();
try
{
ftpclient.connect(hostName,portNumber);//FTP
Connection
ftpclient.setSoTimeout(soTimeOut);//set socket
timeout
isFTPConnected = true;
tempEndTime = System.currentTimeMillis();
connectionTime = tempEndTime - tempStartTime;
}
catch(Exception ex)
{
exceptionErrorMsg = Util.trim(ex.getMessage());
errorcode = Constants.DC_CONNECT_ERR;
}
if(isFTPConnected)
{
EUMLog.log(module, monitorid+" : FTP Connected
Sucessfully : Duration="+connectionTime);
tempStartTime=0L;
tempEndTime=0L;
/*
* FTP Login
*/
tempStartTime = System.currentTimeMillis();
try
{
isLoggedIn =
ftpclient.login(userName,password);
}
catch(Exception ex)
{
exceptionErrorMsg =
Util.trim(ex.getMessage());
errorcode =
Constants.FTP_AUTHENTICATION_FAILED;
EUMLog.log(module, monitorid+" : FTP
Login : Exception : "+exceptionErrorMsg);
if(printlogs)
{
EUMLog.log(module,
Util.getStackTrace(ex));
}
}
tempEndTime = System.currentTimeMillis();
if(isLoggedIn)
{
loginTime = tempEndTime - tempStartTime;
EUMLog.log(module, monitorid+" : FTP
Logged in Sucessfully : Duration="+loginTime);
if(ftpConnectionMode==Constants.FTP_CONNECTION_MODE_PASSIVE)
{
ftpclient.enterLocalPassiveMode();
}
ftpclient.setFileType(FTP.BINARY_FILE_TYPE);
ftpclient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
tempStartTime=0L;
tempEndTime=0L;
/*
* FTP Upload File from Local to Remote
Server
*/
if(uploadEnabled &&
localSourceFileName.length()>0 && remoteDestinationFileName.length()>0)
{
EUMLog.log(module, monitorid+"
: FTP Upload : Starting...");
File localFile = new
File(localSourceFileName);
/*
* Check if the file is present
in the local server
*/
if(localFile.exists())
{
uploadSize =
localFile.length();
uploadSizeInKB =
Util.getSizeInKB(uploadSize);
uploadSizeInMB =
Util.getSizeInMB(uploadSize);
if(isWithinTransferLimit(uploadSize))
{
String sFile[]
= ftpclient.listNames(remoteDestinationFolder);
/*
* Check if the
destination directory is available in the remote server
*/
if(sFile!=null)
{
/*
*
Upload File from local serevr to remote server
*/
tempStartTime = System.currentTimeMillis();
fis =
new FileInputStream(new File(localSourceFileName));
boolean
fileUploadStatus = ftpclient.storeFile(remoteDestinationFileName,fis);
tempEndTime = System.currentTimeMillis();
EUMLog.log(module, monitorid+" : FTP FileUploadStatus="+fileUploadStatus+",
Start="+tempStartTime+", End="+tempEndTime+",
Duration="+(tempEndTime-tempStartTime));
if(fileUploadStatus)
{
uploadTime = tempEndTime - tempStartTime;
if(uploadTime>0)
{
uploadTimeInKBperSec = uploadSizeInKB / ((double)uploadTime/1000.0);
}
}
else
> FTPClient Hangs on connect method and never timeout
> ---------------------------------------------------
>
> Key: NET-548
> URL: https://issues.apache.org/jira/browse/NET-548
> Project: Commons Net
> Issue Type: Bug
> Components: FTP
> Affects Versions: 2.0
> Reporter: Raj
>
> Periodically, we are experiencing the FTP client thread is hang when we
> initiate a connection to the FTP server. See the following thread dump from
> WAS server. It seem like
> after the common net FTP.sendCommand, it will call the
> "FTP.__getReply()" to get the status code, and this should be the point that
> causing the thread hang.
> There is no Socket connection timeout error be thrown, and the thread
> justhang there forever.
> here is the Thread Dump.. Please provide your guidance as to what is wrong
> here and how can we fix it.
> at java/net/SocketInputStream.socketRead0(Native Method)
> at java/net/SocketInputStream.read(SocketInputStream.java:155(Compiled Code))
> at java/net/SocketInputStream.read(SocketInputStream.java:116(Compiled Code))
> at
> sun/nio/cs/StreamDecoder$ConverterSD.implRead(StreamDecoder.java:346(Compiled
> Code))
> at sun/nio/cs/StreamDecoder.read(StreamDecoder.java:252(Compiled Code))
> at java/io/InputStreamReader.read(InputStreamReader.java:212(Compiled Code))
> at java/io/BufferedReader.fill(BufferedReader.java:126(Compiled Code))
> at java/io/BufferedReader.readLine(BufferedReader.java:320(Compiled Code))
> at java/io/BufferedReader.readLine(BufferedReader.java:383(Compiled Code))
> at org/apache/commons/net/ftp/FTP.__getReply(FTP.java:291(Compiled Code))
> at org/apache/commons/net/ftp/FTP.sendCommand(FTP.java:490(Compiled Code))
> at org/apache/commons/net/ftp/FTP.sendCommand(FTP.java:534(Compiled Code))
> at org/apache/commons/net/ftp/FTP.pass(FTP.java:701(Compiled Code))
> at org/apache/commons/net/ftp/FTPClient.login(FTPClient.java:630(Compiled
> Code))
> In the Code..
> we are setting connection timeout & data timeout before FTPClient.connect
> method being called.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)