Souvik
Souvik

Reputation: 1269

Upload file FTP server

I am stuck during connecting to my FTP server through apache FTP client. I found lots of program out there but I am not able to connect to my FTP server through the below code.

FTPClient ftpClient = new FTPClient();
ftpClient.connect("169.144.76.33");
ftpClient.login("root", "re123set");

Exception:

java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
    at java.net.Socket.connect(Socket.java:546)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:176)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:268)

But whenever I am trying to connect through FileZilla with IP, user name, password, port (without port can't connect). I am getting able to connect to the FTP server.

So please help me to resolve the issue..

Upvotes: 2

Views: 2168

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202098

From the fact you need to enter a port in FileZilla (which defaults to the FTP port 21), I assume, you are not providing some information to the FTPClient:

  1. Port number (assuming it's different from the default 21). To connect to a non-default port, use the Connect overload with two arguments:

    public void connect(String hostname, int port)
    
  2. You may be using an implicit SSL/TLS encryption, what FileZilla (but not the FTPClient) could assume from a port number 990

  3. You actually want to use the SFTP (based on the sftp tag with your question). The FTPClient does not support the SFTP protocol, it's totally distinct from the FTP. See How to retrieve a file from a server via SFTP?

Upvotes: 1

Related Questions