Android FTP listfiles () is always 0

Source: Internet
Author: User

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 ();

Related Article

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.