Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
FTP List Directory ContentsDownloads: MS Windows Visual C/C++ Libraries Linux/CentOS C/C++ Libraries MAC OS X C/C++ Libraries Solaris C/C++ Libraries C++ Builder Libraries FreeBSD C++ Libraries HP-UX C++ Libraries BlackBerry QNX C++ Libraries C++ code to list the files and directories within the current remote directory on an FTP server. // Get file and directories in the current (remote) working directory.
// Fetches each filename, size, isDirectory, and last-mod date/time.
void FtpListDir(void)
{
CkFtp2 ftp;
ftp.UnlockComponent("anything for 30-day trial");
ftp.put_Hostname("ftp.chilkatsoft.com");
ftp.put_Username("****");
ftp.put_Password("****");
// non-passive (active) connections are most likely to work if firewalls are present.
ftp.put_Passive(false);
// Connect to the FTP server and login.
bool success = ftp.Connect();
if (!success)
{
ftp.SaveLastError("ftpLog.txt");
return;
}
// List the files in the FTP account's home directory.
ftp.put_ListPattern("*");
int i;
int n = ftp.get_NumFilesAndDirs();
FILETIME fTime;
SYSTEMTIME sysTime;
CkString str;
for (i=0; i<n; i++)
{
// Print the filename and size.
ftp.GetFilename(i,str);
printf("%s -- %d bytes",str.getString(),ftp.GetSize(i));
// Is this a directory or file?
if (ftp.GetIsDirectory(i))
{
printf(" [DIRECTORY]");
}
// Get the last-modified time of the file.
ftp.GetLastModifiedTime(i,fTime);
FileTimeToSystemTime(&fTime,&sysTime);
printf(" %02d:%02d %02d/%02d/%d\n",sysTime.wHour,sysTime.wMinute,
sysTime.wMonth,sysTime.wDay,sysTime.wYear);
}
ftp.Disconnect();
}
|
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.