commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gaspar Medina <gasweb...@gmail.com>
Subject [net] FtpClient _ Connection Reset
Date Tue, 22 Dec 2015 16:49:52 GMT
Hi all.

I am having problems downloading a large file from an FTP server.



I'm using commons-net-3.3.jar, to connect and download the file.



The error I'm getting is an exception of java.net.SocketException type:
Connection reset.



I get this error when I try to process a large file parts.

The web application that is responsible for processing this file is hosted
on a Tomcat that has 1GB of RAM.



I'm trying to process a 500MB file, if the file directly process I try, I
get a stack overflow java.



For the file I am using the following code, for small files.





getFtpConnection public InputStream (string filename) {

InputStream inputStream = null;

FtpClient FtpClient = connection.getConnection (host, port, user, password);

ftpClient.enterLocalPassiveMode ();



InputStream inputStreamProcesado = null;

try {

ftpClient.getReplyCode reply = int ();

if (! FTPReply.isPositiveCompletion (reply)) {

ftpClient.disconnect ();

LOGGER.error ("FTP server connection refused.");

}

try {

ftpClient.mlistFile (filename);

} Catch (Exception e) {

LOGGER.error (e);

}

System.currentTimeMillis long initRetrieveTime = ();

LOGGER.info (String.format ("Starting parsing the file% s", filename));

ftpClient.retrieveFileStream inputStream = (filename);

inputStreamProcesado = procesarRespuestaFTP (inputStream);

System.currentTimeMillis long finalRetrieveTime = ();

LOGGER.info (String.format ("Data obtained in file% s% s", fileName,

DateUtil.timeToString (finalRetrieveTime - initRetrieveTime)));



if (inputStream == null) {

throw new FileNotFoundOnRemoteSiteException (

String.format) (, fileName, FTP_ILIST_SITE "No file% s% s at the site was
found");

}

} Catch (IOException IOE) {

LOGGER.error (ioe.getMessage (), IOE);

} Catch (FileNotFoundOnRemoteSiteException faith) {

LOGGER.error (fe.getMessage (), faith);

}

inputStreamProcesado return;

}



procesarRespuestaFTP private InputStream (InputStream inputStreamAProcesar)
throws IOException {

byte [] bytes = IOUtils.toByteArray (inputStreamAProcesar);

LOGGER.info ("Size:" + bytes.length + "Bytes");

InputStreamFinal = new InputStream ByteArrayInputStream (bytes);

inputStreamFinal return;

}





For large files I try to read the bytes obtained from the FTP in parts, so
that information processing and memory available to continue processing the
file. It turns out that in the middle of this processing parts, I get this
unexpected exception. Someone could help me ?!



I thought about a solution that can get this exeption FTP server reconnect
and continue downloading the remaining bytes needed to complete the file
download.



Thank you.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message