FTPClient uses 'active mode' by default, which is problematic as it requires FTP client to open a port for FTP server to connect back. Using a passive mode should circumvent this issue. After connecting and logging in, add the following line in your FTP code.
FTPClient ftp = new FTPClient();
// connect and login code here
ftp.enterLocalPassiveMode();
This should fix your problem.
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteimport org.apache.commons.net.ftp.FTPClient;
ReplyDeleteimport java.io.IOException;
public class FtpConnectDemo {
public static void main(String[] args) {
FTPClient client = new FTPClient();
try {
client.connect("ftp.hikejabalpur.com");
// When login success the login method returns true.
boolean login = client.login("anshul@hikejabalpur.com", "12345689");
client.enterLocalPassiveMode();
if (login) {
System.out.println("Login success...");
// When logout success the logout method returns true.
boolean logout = client.logout();
if (logout) {
System.out.println("Logout from FTP server...");
}
} else {
System.out.println("Login fail...");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
// Closes the connection to the FTP server
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
same error !
org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection.
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:360)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:290)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:474)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:547)
at org.apache.commons.net.ftp.FTP.user(FTP.java:693)
at org.apache.commons.net.ftp.FTPClient.login(FTPClient.java:872)
at javaapplication1.FtpConnectDemo.main(FtpConnectDemo.java:19)
Please help me sir !!
:D