Using Apache Commons Net APIs

I am making a program to connect to an FTP server using the FTPCLient API class apache commons net. here is the code:

    FTPClient client = new FTPClient();
    byte[] b = new byte[4];
    b[ 0] = new Integer(127).byteValue();
    b[ 1] = new Integer(0).byteValue();
    b[ 2] = new Integer(0).byteValue();
    b[ 3] = new Integer(1).byteValue();
    try{

            InetAddress address = InetAddress.getByAddress(b);
        client.connect(address,22);

       }

..... I get an exception in the connection string ().

org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
+3
source share
1 answer

Try with this

 FTPClient f = new FTPClient();
 f.connect(server);
 f.login(username, password);
 FTPFile[] files = listFiles(directory);

Note: port 22 is used for SSH, sftp is not for ftp

If it is sftp, you need to go commons-vfs

+2
source

Source: https://habr.com/ru/post/1786851/


All Articles