Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

November 30, 2007

FTP2.NumFilesAndDirs — Special considerations

The Ftp2.NumFilesAndDirs property returns the count of files and sub-directories in the current remote FTP directory, according to the ListPattern property. For example, if ListPattern is set to "*.xml", then NumFilesAndDirs returns the count of XML files in the remote directory.

The 1st time it is accessed, the component will (behind the scenes) fetch the directory listing from the FTP server. This information is cached in the component until (1) the current remote directory is changed, or (2) the ListPattern is changed, or (3) the ClearDirCache method is called.

The problem with the NumFilesAndDirs property is that it may return -1 if the behind-the-scenes directory listing download fails. Therefore, using it in a FOR loop like this is a bad idea:

for (i = 0; i <= ftp.NumFilesAndDirs - 1; i++) {
	
...
	
}

It’s better to do this:

int n = ftp.NumFilesAndDirs;
if (n < 0) {
   // Display the ftp.LastErrorText and return..
} else if (n > 0) {
    for (i = 0; i <= ftp.NumFilesAndDirs - 1; i++) {
...
	
    }
}


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.