简体   繁体   中英

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 file zilla 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..

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM