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