FTP response 421 received. Server closed connection

crazyproton picture crazyproton · Jul 17, 2014 · Viewed 49.4k times · Source

I am writing a JAVA code to traverse FTP Location using Apache Commons Net FTPClient and getting output in an Excel file. the code execute correctly for approx 5 min but then gives an IOException:

org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received.  Server closed connection.

I am using commons-net-3.0.1.jar. I have done some R&D and tried:

setDefaultTimeout(6000); 
setConnectTimeout(3000);
setSoTimeout(3000);
enterLocalPassiveMode();

and sending NOOP, but still getting the same error.

All I am trying to do is traverse through a directory and if file is found than get file name and file update date in excel else if directory is found then get inside and do until file is found again.

Please help and ask if any other information is required. I am new to JAVA.

Answer

fiffy picture fiffy · Jul 17, 2014

See here: http://kb.globalscape.com/KnowledgebaseArticle10142.aspx

    Error 421 Service not available, closing control connection. 
    Error 421 User limit reached 
    Error 421 You are not authorized to make the connection 
    Error 421 Max connections reached 
    Error 421 Max connections exceeded 

Maybe you're not reusing a connection but using a new connection for every request, flooding the server with connections until it hits the connection limit. Try closing your connections or resuing them.