Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
24.2k views
in Java FTP by (160 points)
Hi, I use the client (runing on Windows XP) to connect to my FTP server (on VMware, Fedora 5, vsftpd) and got the following exceptions:


java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:364)
at java.net.Socket.connect(Socket.java:507)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)FTP Connection Error: IOException Connection refused: connect

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.enterprisedt.net.ftp.internal.SocketUtils.createSocket(SocketUtils.java:94)
at com.enterprisedt.net.ftp.FTPControlSocket.<init>(FTPControlSocket.java:310)
at com.enterprisedt.net.ftp.FTPClient.connect(FTPClient.java:862)
at com.enterprisedt.net.ftp.FileTransferClient.connect(FileTransferClient.java:367)
at envgui.GuiFrame.jMenuItem1_actionPerformed(GuiFrame.java:67)



I can use the ftp command in DOS to connect with the FTP server:
C:\Documents and Settings\frank>ftp 192.168.1.111
Connected to 192.168.1.111.
220 (vsFTPd 2.0.4)
User (192.168.1.111:(none)): root
331 Please specify the password.
Password:
230 Login successful.
ftp>

My Java code is:
FileTransferClient ftp = new FileTransferClient();
try{
ftp.setRemoteHost(si.ftpip); //si.ftpip = 192.168.1.111
ftp.setRemotePort(si.ftpport); // = 23
ftp.setUserName(si.ftpusr); // = root
ftp.setPassword(si.ftppwd); // = 11122233
// ftp.setTimeout(60000);
// ftp.getAdvancedSettings().setAutoLogin(false);
ftp.connect();
// ftp.manualLogin();
}catch(FTPException fe){
System.out.println("FTP Connection Error: FTPException " + fe.getMessage());
}catch(IOException ie){
System.out.println("FTP Connection Error: IOException " + ie.getMessage());
ie.printStackTrace();
}

Even though I uncomment those lines above, the problems are still the same. (I have debuged the program, si.* is correct)

Is anybody can help me with that? Thanks!

9 Answers

0 votes
by (160 points)
I have solved the problem, it is my application's problem. Many thanks!
0 votes
by (260 points)
Hi
I have the same problem. Do you remember how you solve it?

Thanks
0 votes
by (161k points)
Try ftp.exe from the DOS command line.

If that works, make sure your port number is 21 and the hostname is correct. And use active mode (which is what ftp.exe uses).
0 votes
by (260 points)
Hi
I have tried with active and passive mode, and not works.
I don't know what happens. Probably is because a proxy server, but I don't know how solve it.
In msdos ftp works well.
0 votes
by (161k points)
If MSDOS ftp works, it should also work. Post the log file and we'll take a look.
0 votes
by (260 points)
This is the program that I execute

try
{
FileTransferClient ftp = new FileTransferClient();
ftp.setTimeout(60000);
ftp.setRemoteHost("10.81.114.10"); // FTP server IP
ftp.setUserName("ftpdc2");
ftp.setPassword("testPassw");
ftp.setRemotePort(21);
ftp.connect();
ftp.changeDirectory("/users");
ftp.changeDirectory("ftpdc2");
System.out.println("connect mode=" + ftp.getAdvancedFTPSettings().getConnectMode());
FTPFile[] list2 = ftp.directoryList();
ftp.disconnect(true);
}
catch (Exception e)
{
e.printStackTrace();
}

This is the log result. As you see, when it excute the command PORT, the address received is 10.84.144.8 (the FTP address where I try to connect is 10.84.144.10). This is because a Lisa Server firewall.

C:\dc2error>java TestConn
DEBUG [FTPClient] 29 jul 2009 10:40:28.182 : Class: com.enterprisedt.net.ftp.FTP
Client
Location: file:/C:/dc2error/edtftpj.jar
Version: 2.0.4
Build timestamp: 13-Feb-2009 15:09:20 EST
Java version: 1.6.0
CLASSPATH: .;./ojdbc14.jar;.;./ojdbc14.jar;.;./edtftpj.jar;./ojdbc14.jar;./junit
.jar;.;./ojdbc14.jar;
OS name: Windows XP
OS arch: x86
OS version: 5.1

DEBUG [FileTransferClient] 29 jul 2009 10:40:28.197 : Configured client
DEBUG [FTPClient] 29 jul 2009 10:40:28.197 : Connecting to /10.81.114.10:21
DEBUG [SocketUtils] 29 jul 2009 10:40:28.197 : Invoking connect with timeout=60000
DEBUG [SocketUtils] 29 jul 2009 10:40:28.244 : Connected successfully
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.275 : 220 odin FTP server (Revision 3.0 Version wuftpd-2.6.1 Wed Dec 19 08:45:38 GMT 2007) ready.
DEBUG [FileTransferClient] 29 jul 2009 10:40:28.275 : Client connected
DEBUG [FileTransferClient] 29 jul 2009 10:40:28.275 : Logging in
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.275 : ---> USER ftpdc2
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.307 : 331 Password required for ftpdc2.
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.307 : ---> PASS ********
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.353 : 230 User ftpdc2 logged in.
DEBUG [FileTransferClient] 29 jul 2009 10:40:28.353 : Logged in
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.353 : ---> TYPE I
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.369 : 200 Type set to I.
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.369 : ---> CWD /users
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.400 : 250 CWD command successful.
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.400 : ---> CWD ftpdc2
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.432 : 250 CWD command successful.
connect mode=Active
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.447 : ---> SYST
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.478 : 215 UNIX Type: L8
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.478 : ---> PWD
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.510 : 257 "/users/ftpdc2" is current directory.
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.510 : ListenOnAllInterfaces=true
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.525 : ---> PORT 10,84,144,8,5,105
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.541 : 200 PORT command successful.

DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.541 : ---> LIST
DEBUG [FTPControlSocket] 29 jul 2009 10:40:28.603 : 425 Can't build data connection: Connection refused.
DEBUG [FTPActiveDataSocket] 29 jul 2009 10:40:28.603 : Calling accept()
DEBUG [FTPClient] 29 jul 2009 10:41:28.605 : Validate transfer on error after exception : Accept timed out
java.net.SocketTimeoutException: Accept timed out
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
at java.net.ServerSocket.implAccept(ServerSocket.java:450)
at java.net.ServerSocket.accept(ServerSocket.java:421)
at com.enterprisedt.net.ftp.internal.FTPActiveDataSocket.acceptConnection(FTPActiveDataSocket.java:129)
at com.enterprisedt.net.ftp.internal.FTPActiveDataSocket.getInputStream(FTPActiveDataSocket.java:153)
at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3351)
at com.enterprisedt.net.ftp.FTPClient.dirDetails(FTPClient.java:3282)
at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:568)
at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:554)
at TestConn.test(TestConn.java:30)
at TestConn.main(TestConn.java:42)


java.net.SocketTimeoutException: Accept timed out
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
at java.net.ServerSocket.implAccept(ServerSocket.java:450)
at java.net.ServerSocket.accept(ServerSocket.java:421)
at com.enterprisedt.net.ftp.internal.FTPActiveDataSocket.acceptConnection(FTPActiveDataSocket.java:129)
at com.enterprisedt.net.ftp.internal.FTPActiveDataSocket.getInputStream(FTPActiveDataSocket.java:153)
at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3351)
at com.enterprisedt.net.ftp.FTPClient.dirDetails(FTPClient.java:3282)
at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:568)
at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:554)
at TestConn.test(TestConn.java:30)
at TestConn.main(TestConn.java:42)
ERROR [FTPControlSocket] 29 jul 2009 10:41:29.105 : Read failed ('' read so far)

WARN [FTPClient] 29 jul 2009 10:41:29.105 : Validate transfer on error failed : Read timed out
com.enterprisedt.net.ftp.ControlChannelIOException: Read timed out
at com.enterprisedt.net.ftp.FTPControlSocket.readLine(FTPControlSocket.java:962)
at com.enterprisedt.net.ftp.FTPControlSocket.readReply(FTPControlSocket.java:997)
at com.enterprisedt.net.ftp.FTPClient.validateTransfer(FTPClient.java:2347)
at com.enterprisedt.net.ftp.FTPClient.validateTransferOnError(FTPClient.java:2379)
at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3362)
at com.enterprisedt.net.ftp.FTPClient.dirDetails(FTPClient.java:3282)
at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:568)
at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:554)
at TestConn.test(TestConn.java:30)
at TestConn.main(TestConn.java:42)


com.enterprisedt.net.ftp.ControlChannelIOException: Read timed out
at com.enterprisedt.net.ftp.FTPControlSocket.readLine(FTPControlSocket.java:962)
at com.enterprisedt.net.ftp.FTPControlSocket.readReply(FTPControlSocket.java:997)
at com.enterprisedt.net.ftp.FTPClient.validateTransfer(FTPClient.java:2347)
at com.enterprisedt.net.ftp.FTPClient.validateTransferOnError(FTPClient.java:2379)
at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3362)
at com.enterprisedt.net.ftp.FTPClient.dirDetails(FTPClient.java:3282)
at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:568)
at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:554)
at TestConn.test(TestConn.
0 votes
by (161k points)
One difference is the IP the server is being asked to connect back to:

PORT 10,84,145,64 (success)

and

PORT 10,84,144,8 (failure)

Is the second IP address valid for the server? You can set the IP address in the advanced settings (setActiveIPAddress())
0 votes
by (260 points)
I have run de program with setActiveIPAddress and not works.
This is the structure of the net:

----------
| PC | 10.84.145.64
----------
|
|
-------------
| FIREWALL | 10.84.144.8 (NAT)
-------------
|
|
----------------
| FTP SERVER | 10.80.114.10
----------------

Now I have run this code with the firewall on:

try
{
FileTransferClient ftp = new FileTransferClient();
ftp.setTimeout(60000);
ftp.setRemoteHost("10.81.114.10"); // FTP server IP
ftp.setUserName("ftpdc2");
ftp.setPassword("testPassw");
ftp.setRemotePort(21);
ftp.getAdvancedFTPSettings().setActiveIPAddress("10.84.145.64");
ftp.connect();
ftp.changeDirectory("/users");
ftp.changeDirectory("ftpdc2");
System.out.println("connect mode=" + ftp.getAdvancedFTPSettings().getConnectMode());
FTPFile[] list2 = ftp.directoryList();
ftp.disconnect(true);
}
catch (Exception e)
{
e.printStackTrace();
}


and log result is this:


C:\dc2error>java TestConn
DEBUG [FTPClient] 30 jul 2009 10:49:23.855 : Class: com.enterprisedt.net.ftp.FTPClient
Location: file:/C:/dc2error/edtftpj.jar
Version: 2.0.4
Build timestamp: 13-Feb-2009 15:09:20 EST
Java version: 1.6.0
CLASSPATH: .;./ojdbc14.jar;.;./ojdbc14.jar;.;./ojdbc14.jar;.;./ojdbc14.jar;.;./o
jdbc14.jar;.;./edtftpj.jar;./ojdbc14.jar;./junit.jar;
OS name: Windows XP
OS arch: x86
OS version: 5.1

DEBUG [FileTransferClient] 30 jul 2009 10:49:23.871 : Configured client
DEBUG [FTPClient] 30 jul 2009 10:49:23.871 : Connecting to /10.81.114.10:21
DEBUG [SocketUtils] 30 jul 2009 10:49:23.886 : Invoking connect with timeout=60000
DEBUG [SocketUtils] 30 jul 2009 10:49:23.933 : Connected successfully
DEBUG [FTPControlSocket] 30 jul 2009 10:49:23.949 : 220 odin FTP server (Revision 3.0 Version wuftpd-2.6.1 Wed Dec 19 08:45:38 GMT 2007) ready.
DEBUG [FileTransferClient] 30 jul 2009 10:49:23.964 : Client connected
DEBUG [FileTransferClient] 30 jul 2009 10:49:23.964 : Logging in
DEBUG [FTPControlSocket] 30 jul 2009 10:49:23.964 : ---> USER ftpdc2
DEBUG [FTPControlSocket] 30 jul 2009 10:49:23.996 : 331 Password required for ftpdc2.
DEBUG [FTPControlSocket] 30 jul 2009 10:49:23.996 : ---> PASS ********
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.043 : 230 User ftpdc2 logged in.
DEBUG [FileTransferClient] 30 jul 2009 10:49:24.043 : Logged in
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.043 : ---> TYPE I
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.058 : 200 Type set to I.
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.074 : ---> CWD /users
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.089 : 250 CWD command successful.
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.089 : ---> CWD ftpdc2
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.121 : 250 CWD command successful.
connect mode=Active
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.136 : ---> SYST
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.152 : 215 UNIX Type: L8
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.168 : ---> PWD
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.199 : 257 "/users/ftpdc2" is current directory.
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.199 : ListenOnAllInterfaces=true
INFO [FTPControlSocket] 30 jul 2009 10:49:24.199 : Forcing use of fixed IP for PORT command
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.199 : ---> PORT 10,84,145,64,5,81
DEBUG [FTPControlSocket] 30 jul 2009 10:49:24.230 : 500 Illegal PORT Command
INFO [FTPControlSocket] 30 jul 2009 10:49:24.230 : Expected reply codes = [200,250]
com.enterprisedt.net.ftp.FTPException: 500 Illegal PORT Command
at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(FTPControlSocket.java:1127)
at com.enterprisedt.net.ftp.FTPControlSocket.setDataPort(FTPControlSocket.java:756)
at com.enterprisedt.net.ftp.FTPControlSocket.sendPORTCommand(FTPControlSocket.java:632)
at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocketActive(FTPControlSocket.java:576)
at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocket(FTPControlSocket.java:544)
at com.enterprisedt.net.ftp.FTPClient.setupDataSocket(FTPClient.java:2452)
at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:3324)
at com.enterprisedt.net.ftp.FTPClient.dirDetails(FTPClient.java:3282)
at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:568)
at com.enterprisedt.net.ftp.FileTransferClient.directoryList(FileTransferClient.java:554)
at TestConn.test(TestConn.java:34)
at TestConn.main(TestConn.java:47)

C:\dc2error>


If I put the firewall off and execute the same code, the program works well.
Do you see something wrong?

Thanks
0 votes
by (161k points)
I think you probably need to talk to your firewall administrator ...

Categories

...