<< Back
// SampleC-Listing.c : Sample FTP Voyager SDK Application
//
// Copyright © 1997-2006 - Rhino Software, Inc.
// FTP Voyager® is a registered trademark of Rhino Software, Inc.
// http://www.RhinoSoft.com/
//
// Author:  Mark P. Peterson
// Date:    September 27, 2005
//
// You are free to use/modify this code but leave this header intact.
// This code is public domain so you are free to use it in any of your
// applications (Freeware, Trialware, Commercial, etc.).  FTP Voyager,
// the FTP Voyager Software Development Kit, and FtpTree ActiveX Control
// are not public domain.  Any registration IDs or non-public domain software
// from Rhino Software, Inc. remains copyrighted.  For more information,
// refer to the license agreement distributed with the FTP Voyager SDK.
//
// If you decide to use the FTP Voyager Software Development Kit, or FtpTree
// ActiveX control, you must first purchase a license.  For more information
// visit http://www.RhinoSoft.com/
//------------------------------------------------------------------------------
//
// The following program is a simple C language program designed to help learn
// the following FTP Voyager Software Development Kit concepts:
//
//   * creating an FVSDK_Session
//   * settting the required FVSDK_Session members
//   * connecting to the server
//   * performing a directory listing
//   * disconnecting from the server
//   * freeing the session
//
//------------------------------------------------------------------------------

#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