commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Watts <nick.a.wa...@gmail.com>
Subject Re: [net] FTPClient retrieveFile doesn't finish
Date Wed, 18 May 2016 15:20:31 GMT
Hi Victor. If a file is not being completely received from the FTP server,
I'd first try to figure out why that happened. It sounds like a problem
with the FTP server or the file itself.

As to the specific retrieveFile question you asked, I don't think it's fair
to say that it is "hanging".
The retrieveFile method only knows to return or throw an exception when it
receives an FTP status code of some sort. If it never receives a status
code, it will continue to wait indefinitely. Since there's no way to
foretell how long a file will take to download, you wouldn't really want to
set a timeout anyway as you could prematurely cut off a download that is
slow but otherwise proceeding without error.

Given this, you're probably stuck with having to monitor the state of the
connection and the local file output stream yourself. This is not trivial,
as you can imagine. You would need your own timeout configuration, cleanup
code, perhaps a separate thread on which to do the monitoring, etc....

With the programs that I've used Commons Net on, I just skip all that
complexity and let the files take as long as necessary to download. In
other words, for my use cases, it is acceptable for me to have to kill the
Java process and restart if a file is not fully received after an unusual
amount of time.

I can't recall that I've ever actually had one take an unexpected amount of
time but when that does happen, I'll look to the source of the file first
;)


On Thu, May 12, 2016 at 5:42 PM, Victor Rodriguez <vrodrigu@digitalglobe.com
> wrote:

> ?Hi!
>
>
> I'm having an issue where sometimes FTPClient.retrieveFile doesn't finish
> and it doesn't timeout either.
>
>
> ftpClient.enterLocalPassiveMode();
> ftpClient.setControlKeepAliveTimeout(60);
> ftpClient.setControlKeepAliveReplyTimeout(60000);
> ftpClient.setDataTimeout(60000);
> ftpClient.setBufferSize(8256000);
> ftpClient.setReceiveBufferSize(8256000);
> ftpClient.setReceieveDataSocketBufferSize(8256000);
>
> The BufferedOutputStream I'm using is defined as follows...
>
> outputStream = new BufferedOutputStream(new FileOutputStream(localFile),
> 8256000);
>
> What I'm doing is connecting, logging in, transferring a bunch of files
> one at a time, logging out, disconnecting.  Is there any way I can prevent
> retrieveFile from hanging or make it so that retrieveFile times out after a
> while so that I can try again?  If there is no configurable timeout, what
> strategies are people using to interrupt the call to retrieveFile and try
> again?
>
> Thoughts?
>
> Thanks!
>
> Victor
>
> This electronic communication and any attachments may contain confidential
> and proprietary information of DigitalGlobe, Inc. If you are not the
> intended recipient, or an agent or employee responsible for delivering this
> communication to the intended recipient, or if you have received this
> communication in error, please do not print, copy, retransmit, disseminate
> or otherwise use the information. Please indicate to the sender that you
> have received this communication in error, and delete the copy you received.
>
> DigitalGlobe reserves the right to monitor any electronic communication
> sent or received by its employees, agents or representatives.
>



-- 
Nick Watts
blog: thewonggei.wordpress.com
twitter: @thewonggei

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