Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.8k views
in Java FTP by (200 points)
Hi,
I am starting out writing a FTP client.

String host = "hostname";        
        String user = "testuser";
        String password = "mango";

FTPClient ftp = null;
ftp = new FTPClient();
ftp.setRemoteHost(host);

 FTPMessageCollector listener = new FTPMessageCollector();
 ftp.setMessageListener(listener);
            
// connect
System.out.println("Connecting");
ftp.connect();

System.out.println("Logging in");
ftp.login(user, password);



When I run this, its prints out "Connecting" and then I get this exception:
java.net.ConnectException: Connection refused: connect


What could be wrong? This code is from the demo program that came with the download..

6 Answers

0 votes
by (220 points)
Have you tried using an FTP client (such as CuteFTP, SmartFTP, FileZilla, etc.) to see if you can connect to the FTP server you are using for testing?

Or, if developing on a Windows machine, you can open an MSDOS shell and type:

ftp <hostname>



There is probably something similar on UNIX/Linix -- Mac ???

Things to consider:

1. Typo in host name
2. Firewall
3. FTP Server down

BTW: I have sucessfully connected using the same code that you displayed in your post.
0 votes
by (162k points)
Hey Steve, many thanks for your very useful contributions on the forums.
0 votes
by (200 points)
I tried connecting using "WS-FTP" client for same host, user name and it connects successfully.

It must be either the firewall (which I doubt, because I am within the system) or no FTP service running on the server.
0 votes
by (162k points)
Post a snippet of the log file.

Also, try 'telnet hostname 21' - that connects to the FTP port. If the connection is refused there is no server listening on that port.
0 votes
by (200 points)
I tried the telnet you'd mentioned.

I got this:

Connecting To <hostname>...Could not open connection to the host, on
port 21: Connect failed
0 votes
by (162k points)
This means there is not an FTP server listening on the standard FTP port (21).

If you can get a log or trace from WS-FTP, please post it. It must be using either a different port or a different protocol. Check the settings.

Categories

...