File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes How to set read timeout for ftp control connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to set read timeout for ftp control connection" Watch "How to set read timeout for ftp control connection" New topic
Author

How to set read timeout for ftp control connection

Michael Rodman
Greenhorn

Joined: Oct 02, 2013
Posts: 6


I am using ftp apache's commomns net version 3.1 .

The ftp connection gets in hung state while doing listing operation INTERMITTENTLY .

The reason i feel so seems to be ftp client is kept waiting indefnitely for server response for FTP command PASV while trying to open data connection for listing operation.

How do i need to set read timeout on control connection to avoid this situation.

I have set readtimeout on data connection using setDataTimeout().

For more refer : http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html#setDataTimeout(int)

1)Does setting setsoTimeout() after doing ftp connect() operation helps avoiding this situation on control connection?

For more refer : http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/SocketClient.html#setSoTimeout(int)

2)If so,what is the optimum timeout value i need to set for setsotimeout() ?

Please find stack trace below:

at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:140)
at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:464)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:506)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:234)
at java.io.InputStreamReader.read(InputStreamReader.java:188)
at java.io.BufferedReader.fill(BufferedReader.java:147)
at java.io.BufferedReader.read(BufferedReader.java:168)
at org.apache.commons.net.io.CRLFLineReader.readLine(CRLFLineReader.java:58
)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:310)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:290)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:479)
at org.apache.commons.net.ftp.FTPClient.openDataConnection(FTPClient.java:7
69)
at org.apache.commons.net.ftp.FTPClient.openDataConnection(FTPClient.java:6
57)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:
3097)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:
3072)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:
2972

Any help on this will be appreciated

Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Hi Michael,

I'm a person who decided it would be a good idea to put a timeout on the FTP control connection. (I forget why I decided it was a good idea.) It wasn't long before I started getting reports that file uploads were being cancelled, and when I investigated I found that if the file upload took longer than the timeout interval I had specified for the control connection, an timeout exception was thrown and the upload was indeed cancelled. So that timeout interval prevented large files from being uploaded.

What I'm trying to say here is that you should really look for a different solution for your problem.
Michael Rodman
Greenhorn

Joined: Oct 02, 2013
Posts: 6
Hi Paul,

Thanks for your reply.

I was referring to read timeout not connection timeout on FTP control channel.

Coming to the problem you stated,we can make sure control connection is not idle for too long by sending ftp NOOP commands on frequent interval while upload/download is in progress on ftp data connection so that control connection does not times out.

But my current issue is when ftp control connection sends FTP control command 'PASV' on control channel for opening data connection ,ftp server does not reply and thus ftp client keeps waiting indefnitely for ftp server response on ftp control channel and it results in hang.

The same issue on ftp data chaanel can be overcommed by using setDataTimeout().

I want to overcome this issue on control channel,so i was asking whether setting setsotimeout() after connecting to ftp server will help to overcome this issue and also needed optimum timeout value to be used ?

any idea ?

Thanks,
Michael
 
Don't get me started about those stupid light bulbs.
 
subject: How to set read timeout for ftp control connection
 
Similar Threads
SocketException while using org.apache.commons.net.ftp.FTPClient
Problem in connecting to FTP server
Getting Exception for Java through FTP.
Connect to FTP site with Apache commons net FTP client through Proxy
java.net.SocketException: Connection reset