Interpreting the LIST results from an FTP server is usually quite complex and involved. Servers are allowed to respond in their native operating system format making cross-platform use of FTP difficult to achieve. The FTP Voyager SDK shields you from these troubles. Listings returned by the FTP Voyager SDK are in a normalized structure that can be used regardless of the server operating system.
For programmers familiar with the Windows API calls for performing directory listings, the FTP Voyager SDK functions work in a similar way. After initializing the session structure and connecting to a server, the FVSDK_FileInfo structure is initialized and FVSDK_FindFile(), FVSDK_FindNextFile(), and FVSDK_FindFileClose() are used to retrieve a directory listing from the server. In the sample C program, SampleC-Listing.c, the contents of the initial directory are printed to the screen.
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "FVSDK_Funcs.h"
int main(int argc, char* argv[])
{
int nRet = 0;
FVSDK_Session* pSession;
// allocate and initialize the session in the SDK
if (FVSDK_NewSession(&pSession) == FVSDK_OK) {
// set the server name to connect to
pSession->pszServer = "ftp.simtel.net";
// try to connect to the server
if (FVSDK_Connect(pSession) == FVSDK_OK) {
// find the file or files in the current directory
if (FVSDK_FindFile(pSession, "*") == FVSDK_YES) {
FVSDK_ERROR_CODE fvecRet;
FVSDK_FileInfo FileInfo;
// initialize the file info structure
FileInfo.nVersion = FVSDK_FILE_INFO_CURRENT_VERSION;
FileInfo.nSize = sizeof(FileInfo);
// find each of the files in the current directory
do {
// get the current file information and move to the next file
fvecRet = FVSDK_FindNextFile(pSession, &FileInfo);
// show the name, type, and size
printf("%s; %s; %I64u\r\n", FileInfo.pszFileName,
((FileInfo.bDirectory) ? "DIR": "FILE"),
FileInfo.fsFileSize);
} while (fvecRet == FVSDK_YES);
} // if
else
nRet = 3;
// close the file find operation
FVSDK_FindFileClose(pSession);
// disconnect from the server
FVSDK_Disconnect(pSession);
} // if
else
nRet = 2;
// close and release the session
FVSDK_FreeSession(pSession);
} // if
else
nRet = 1;
// display any error
if (nRet)
printf("error: %d\r\n", nRet);
// tell the user to press a key on the keyboard
printf("Press any key --> ");
// wait for the user to press a key on the keyboard
getch();
// exit from our application, 0 == success, otherwise an error
return (nRet);
} // main