Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
4.4k views
in Java FTP by (200 points)
Hi, I have a problem with the "exists" method, if it the first call after a connection is made in passive mode.

I'm using the latest version (2.3.0 ) of edtftpj free library.

2 exemples :

try {
FileTransferClient ftp = new FileTransferClient();
ftp.setRemoteHost("myServer");
ftp.setUserName("myUSername");
ftp.setPassword("myPassword");
ftp.setRemotePort(21);
ftp.connect();
ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.PASV);
ftp.exists("anyFile");
} catch(Exception e)
{
e.printStackTrace();
}

KO : com.enterprisedt.net.ftp.FTPException: 500 I won't open a connection to xx.xx.xx.xx (only to yy.yy.yy.yy)
at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(FTPControlSocket.java:1223)
at com.enterprisedt.net.ftp.FTPControlSocket.setDataPort(FTPControlSocket.java:815)
at com.enterprisedt.net.ftp.FTPControlSocket.sendPORTCommand(FTPControlSocket.java:669)
at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocketActive(FTPControlSocket.java:616)
at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocket(FTPControlSocket.java:583)
at com.enterprisedt.net.ftp.FTPClient.setupDataSocket(FTPClient.java:2648)
at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3664)
at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3756)
at com.enterprisedt.net.ftp.FTPClient.dirDetails(FTPClient.java:3583)
at com.enterprisedt.net.ftp.FTPClient.existsFile(FTPClient.java:2065)
at com.enterprisedt.net.ftp.FTPClient.exists(FTPClient.java:2110)
at com.enterprisedt.net.ftp.FileTransferClient.exists(FileTransferClient.java:944)
at com.kewego.commons.util.FtpCopier.main(FtpCopier.java:794)

But if I do :

try {
FileTransferClient ftp = new FileTransferClient();
ftp.setRemoteHost("myServer");
ftp.setUserName("myUSername");
ftp.setPassword("myPassword");
ftp.setRemotePort(21);
ftp.connect();
ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.PASV);
ftp.directoryList();
ftp.exists("anyFile");
} catch(Exception e)
{
e.printStackTrace();
}

OK : There's no problem.

Do you know why it is happening ?

Thank you for your help !

Nelson

4 Answers

0 votes
by (162k points)
Best to post the DEBUG level log file.
0 votes
by (200 points)
Here they are :

KO :


DEBUG [FTPClient] 4 avr. 2012 15:33:12.695 : Class: com.enterprisedt.net.ftp.FTPClient
Location: file:/C:/usr/local/java-lib/edtftpj.jar
Version: 2.3.0
Build timestamp: 26-Aug-2011 13:52:07 EST
Java version: 1.6.0_30
CLASSPATH: C:\usr\local\java-lib\edtftpj.jar
OS name: Windows 7
OS arch: amd64
OS version: 6.1

DEBUG [FileTransferClient] 4 avr. 2012 15:33:12.698 : Configured client
DEBUG [FTPClient] 4 avr. 2012 15:33:12.705 : Connecting to myServer:21
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.721 : 220---------- Welcome to Pure-FTPd [TLS] ----------
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.721 : 220-You are user number 3 of 60 allowed.
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.721 : 220-Local time is now 15:34. Server port: 21.
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.721 : 220-This is a private system - No anonymous login
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.722 : 220-IPv6 connections are also welcome on this server.
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.722 : 220 You will be disconnected after 15 minutes of inactivity.
DEBUG [FileTransferClient] 4 avr. 2012 15:33:12.723 : Client connected
DEBUG [FileTransferClient] 4 avr. 2012 15:33:12.723 : Logging in
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.723 : ---> USER myUser
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.725 : 331 User myUser OK. Password required
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.725 : ---> PASS ********
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.737 : 230-User user has group access to: www
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.737 : 230 OK. Current restricted directory is /
DEBUG [FileTransferClient] 4 avr. 2012 15:33:12.737 : Logged in
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.738 : ---> TYPE I
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.740 : 200 TYPE is now 8-bit binary
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.740 : ---> SIZE anyFile
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.742 : 550 Can't check for file existence
DEBUG [FTPClient] 4 avr. 2012 15:33:12.742 : SIZE not supported - trying MDTM
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.742 : ---> MDTM anyFile
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.745 : 550 Can't check for file existence
DEBUG [FTPClient] 4 avr. 2012 15:33:12.745 : MDTM not supported - trying LIST
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.748 : ---> SYST
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.750 : 215 UNIX Type: L8
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.754 : ---> PWD
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.756 : 257 "/" is your current location
DEBUG [FTPClient] 4 avr. 2012 15:33:12.756 : setupDirDetails(.) returning: /
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.760 : ListenOnAllInterfaces=true
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.761 : ---> PORT x,x,x,x,x,x
DEBUG [FTPControlSocket] 4 avr. 2012 15:33:12.764 : 500 I won't open a connection to x.x.x.x (only to y.y.y.y)
INFO [FTPControlSocket] 4 avr. 2012 15:33:12.764 : Expected reply codes = [200,250]


OK :


DEBUG [FTPClient] 4 avr. 2012 15:32:47.035 : Class: com.enterprisedt.net.ftp.FTPClient
Location: file:/C:/usr/local/java-lib/edtftpj.jar
Version: 2.3.0
Build timestamp: 26-Aug-2011 13:52:07 EST
Java version: 1.6.0_30
CLASSPATH: C:\usr\local\java-lib\edtftpj.jar
OS name: Windows 7
OS arch: amd64
OS version: 6.1

DEBUG [FileTransferClient] 4 avr. 2012 15:32:48.619 : Configured client
DEBUG [FTPClient] 4 avr. 2012 15:32:48.640 : Connecting to myServer:21
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.656 : 220---------- Welcome to Pure-FTPd [TLS] ----------
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.657 : 220-You are user number 3 of 60 allowed.
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.657 : 220-Local time is now 15:33. Server port: 21.
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.658 : 220-This is a private system - No anonymous login
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.658 : 220-IPv6 connections are also welcome on this server.
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.659 : 220 You will be disconnected after 15 minutes of inactivity.
DEBUG [FileTransferClient] 4 avr. 2012 15:32:48.660 : Client connected
DEBUG [FileTransferClient] 4 avr. 2012 15:32:48.660 : Logging in
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.661 : ---> USER myUser
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.663 : 331 User myUser OK. Password required
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.663 : ---> PASS ********
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.675 : 230-User myUser has group access to: www
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.676 : 230 OK. Current restricted directory is /
DEBUG [FileTransferClient] 4 avr. 2012 15:32:48.676 : Logged in
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.676 : ---> TYPE I
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:48.679 : 200 TYPE is now 8-bit binary
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.303 : ---> SYST
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.306 : 215 UNIX Type: L8
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.327 : ---> PWD
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.330 : 257 "/" is your current location
DEBUG [FTPClient] 4 avr. 2012 15:32:49.330 : setupDirDetails() returning: /
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.330 : ---> PASV
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.333 : 227 Entering Passive Mode (x,x,x,x,x,x)
INFO [FTPControlSocket] 4 avr. 2012 15:32:49.333 : Substituting server supplied IP (x.x.x.x) with remote host IP (x.x.x.x)
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.337 : ---> LIST
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.340 : 150 Accepted data connection
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.342 : 226-ASCII
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.342 : 226-Options: -a -l
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.342 : 226 5 matches total
DEBUG [FTPFileFactory] 4 avr. 2012 15:32:49.345 : Confirmed format UNIX
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.722 : ---> SIZE anyFile
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.740 : 550 Can't check for file existence
DEBUG [FTPClient] 4 avr. 2012 15:32:49.742 : SIZE not supported - trying MDTM
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.742 : ---> MDTM anyFile
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.746 : 550 Can't check for file existence
DEBUG [FTPClient] 4 avr. 2012 15:32:49.746 : MDTM not supported - trying LIST
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.749 : ---> PWD
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.753 : 257 "/" is your current location
DEBUG [FTPClient] 4 avr. 2012 15:32:49.753 : setupDirDetails(.) returning: /
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.753 : ---> PASV
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.756 : 227 Entering Passive Mode (x,x,x,x,x,x)
INFO [FTPControlSocket] 4 avr. 2012 15:32:49.756 : Substituting server supplied IP (x.x.x.x) with remote host IP (x.x.x.x)
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.759 : ---> LIST .
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.762 : 150 Accepted data connection
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.764 : 226-ASCII
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.764 : 226-Options: -a -l
DEBUG [FTPControlSocket] 4 avr. 2012 15:32:49.765 : 226 5 matches total
0 votes
by (162k points)
The one that's failing is in active (PORT) mode. The error message is:

500 I won't open a connection to x.x.x.x (only to y.y.y.y)

This means you need to set the active IP address to y.y.y.y via setActiveIPAddress
0 votes
by (200 points)
Thank you for your help. Only next Tuesday It will be possible for me to check again. I will then tell you if it works.

What surprise is that if i call "directoryList()" juste before the "exists()" method works then fine.

Anyway, thank you !

Categories

...