This is because you need to obtain the size of the file to be downloaded in advance to implement multi-threaded FTP download of the same file,
First obtain the file list through listfiles () and then the file size. The Code is as follows:
Ftpfile [] files = ftpclient. listfiles ();
For (INT I = 0; I <files. length; I ++ ){
Ftpfile file = files [I];
String filename = file. getname ();
If (filename. Equals (remotefilename )){
Size = file. getsize ();
}
}
However, when listfiles () is called, the obtained file list is always 0! Because Android cannot establish FTP connect in the main thread. Listfiles () called in the Child thread ()
.
I searched for resources on the Internet and watched datasheet. It never solved the problem.
Found this article: https://issues.apache.org/jira/browse/NET-190
This function is also found in Datasheet,
public FTPListParseEngine initiateListParsing(String parserKey,String pathname)throws IOException
So I tried it and it succeeded!
The Code is as follows:
Ftplistparseengine engine = ftpclient. initiatelistparsing ("org.apache.commons.net. FTP. parser. unixftpentryparser", remotepath );
Ftpfile [] files = engine. getfiles ();