Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.9k views
in Java FTP by (160 points)
Hello,
as described in the subject I'm getting a SocketTimeOutException when calling
FTPClient.exists().
Anything else works fine - to work around this exception I read the whole directory
with FTPClient.directoryNameList() and go through the string array to check if it contains
the file but I would prefer to call exists() if possible.
BTW - I'm connecting to an IBM-mainframe if this is of importance to you.

Here's the log:

Version: 2.0.3
Build timestamp: 6-Jun-2008 14:04:32 EST
Java version: 1.4.2_17
CLASSPATH: C:\ccm\LoadFileEditor\bin;C:\ccm\LoadFileEditor\lib\edtftpj.jar;C:\ccm\LoadFileEditor\lib\jcalendar-1.3.2.jar;C:\ccm\LoadFileEditor\lib\jxl.jar
OS name: Windows 2000
OS arch: x86
OS version: 5.0

DEBUG [FileTransferClient] 10 Jun 2008 10:10:28.223 : Configured client
DEBUG [FTPClient] 10 Jun 2008 10:10:28.223 : Connecting to host-obk/30.255.10.1:21
DEBUG [SocketUtils] 10 Jun 2008 10:10:28.223 : Invoking connect with timeout=60000
DEBUG [SocketUtils] 10 Jun 2008 10:10:28.223 : Connected successfully
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.223 : 220-TCPFTPDL IBM FTP CS V1R9 at SYS1, 08:10:41 on 2008-06-10.
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.364 : 220 Connection will close if idle for more than 5 minutes.
DEBUG [FileTransferClient] 10 Jun 2008 10:10:28.364 : Client connected
DEBUG [FileTransferClient] 10 Jun 2008 10:10:28.364 : Logging in
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.364 : ---> USER XXXXXX
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.364 : 331 Send password please.
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.364 : ---> PASS ********
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.505 : 230 XXXXXX is logged on. Working directory is "XXXXXX.".
DEBUG [FileTransferClient] 10 Jun 2008 10:10:28.505 : Logged in
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.505 : ---> TYPE I
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.505 : 200 Representation type is Image
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.505 : ---> TYPE A
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.520 : 200 Representation type is Ascii NonPrint
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.520 : ---> CWD 'PDBEBS.TABEX.'
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:28.520 : 250 "PDBEBS.TABEX." is working directory name prefix
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:32.317 : ---> SIZE 'PDBEBS.TABEX.LOAD.PARAM'
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:32.333 : 501 command aborted - FTP server not configured for SIZE
DEBUG [FTPClient] 10 Jun 2008 10:10:32.333 : SIZE not supported - trying MDTM
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:32.333 : ---> MDTM 'PDBEBS.TABEX.LOAD.PARAM'
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:32.333 : 501 command aborted - FTP server not configured for MDTM
DEBUG [FTPClient] 10 Jun 2008 10:10:32.349 : MDTM not supported - trying RETR
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:32.364 : ---> PORT 10,101,12,107,10,240
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:32.364 : 200 Port request OK.
DEBUG [FTPControlSocket] 10 Jun 2008 10:10:32.364 : ---> RETR 'PDBEBS.TABEX.LOAD.PARAM'

java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at com.enterprisedt.net.ftp.FTPControlSocket.readReply(FTPControlSocket.java:910)
at com.enterprisedt.net.ftp.FTPControlSocket.sendCommand(FTPControlSocket.java:878)
at com.enterprisedt.net.ftp.FTPClient.exists(FTPClient.java:1867)
at com.enterprisedt.net.ftp.FileTransferClient.exists(FileTransferClient.java:753)
at at.dbeg.lfe.eventhandling.SaveFileAction.paramFileIsEmpty(SaveFileAction.java:78)
at at.dbeg.lfe.eventhandling.SaveFileAction.actionPerformed(SaveFileAction.java:130)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Regards,
Reinhard

2 Answers

0 votes
by (160 points)
I have now looked a little bit into the source code of the FTPClient class...

The problem is:
The FTP-Server I try to connect to does not know about the commands SIZE and MDTM,
so RETR is called.
Before sending RETR, a PORT command is also sent which tells the FTP server to which
port it should send the data. Since we do not want to get the data, the port is closed
immeditately after creating the ServerSocket so in theory we should not get stressed
by getting all the file data.
Excerpt from FTPClient.exists()
...
// ok, now try RETR since nothing else is supported

ServerSocket sock = new ServerSocket(0);
short port = (short)sock.getLocalPort();
sock.close();
control.sendPORTCommand(port);

// send the retrieve command
lastReply = control.sendCommand("RETR " + remoteFile);
char ch = lastReply.getReplyCode().charAt(0);
...

But I think here is the problem - I guess the server sends the response not until
it has established a connection for the data. But this must fail since no one listens
on this port at the client.
So the FTPClient waits and waits for a response that never comes.

I think the only solution is the one I already mentioned - read the directory names
and check whether the wanted file is in the list.
If you know a better solution please let me know!

Regards,
Reinhard
0 votes
by (162k points)
Yes. It's not the greatest way of finding if a file exists, using PORT (although it is a fallback used only if SIZE doesn't work etc). We may end up doing a directory list instead of PORT at some point.

Categories

...