Use the Apache FTP client to obtain the file list on the FTP Server FTP Response 421 resolved ed. Server closed connection

Source: Internet
Author: User
Tags ftp client
Use the Apache FTP client to obtain the file list on the FTP Server FTP Response 421 resolved ed. Server closed connection

@ For & ever 2009-12-09

Use the Apache FTP client (Java open-source package commons-net-2.0) to obtain the file list on the FTP server and write a recursive list () method.
When the number of files on the FTP server is too large, runProgram

Ftpfile [] FS = ftp. listfiles (pathname );
And pass
For (ftpfile F: FS ){
// Todo something
}

The following exception occurs when obtaining the directory list:

Port 192,168
421 timeout.

Org.apache.commons.net. FTP. ftpconnectionclosedexception: FTP Response 421 stored ed. Server closed connection.
At org.apache.commons.net. FTP. FTP. _ getreply (ftp. Java: 346)
At org.apache.commons.net. FTP. FTP. sendcommand (ftp. Java: 490)
At org.apache.commons.net. FTP. FTP. sendcommand (ftp. Java: 534)
At org.apache.commons.net. FTP. FTP. Port (ftp. Java: 862)
At org.apache.commons.net. FTP. ftpclient. _ opendataconnection _ (ftpclient. Java: 463)
At org.apache.commons.net. FTP. ftpclient. initiatelistparsing (ftpclient. Java: 2296)
At org.apache.commons.net. FTP. ftpclient. initiatelistparsing (ftpclient. Java: 2269)
At org.apache.commons.net. FTP. ftpclient. listfiles (ftpclient. Java: 2047)

Therefore, in order to prevent this exception, we had to get rawlisting and parse the string through regular expressions to get the detailed information about the Directory List and the files contained in the directory.

============================================
When the following sections are used, problems often occur.
Public static void list (ftpclient FTP, string pathname, string filename) throws ioexception {
System. Out. println ("-----> enter the Directory:" + pathname );
If (I % 20 = 0 ){
// Ftp. changeworkingdirectory (pathname );
Try {
Writefile (S, filename );
S = "";
} Catch (exception e ){
E. printstacktrace ();
}

Try {
Random r = new random ();
Int n = R. nextint (10 );
Thread. Sleep (N * 1000 );
} Catch (interruptedexception e ){
E. printstacktrace ();
}
}

I ++;
// XXXXXXXXX do something
}

 

@ Forandever 2009-12-09

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.