<< Back
// SampleC-XFer-Manual.c : Sample FTP Voyager SDK Application
//
// Copyright © 1997-2008 - 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
//   * downloading a file in a loop using FVSDK_OpenFile(), FVSDK_ReadFile(),
//     and FVSDK_CloseFile()
//   * 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.rhinosoft.com";

        // try to connect to the server
        if (FVSDK_Connect(pSession) == FVSDK_OK) {

            // attempt to open the file to be downloaded
            if (FVSDK_OpenFile(pSession, "/pub/rhinosoft/00index.txt", FALSE, 0) == FVSDK_YES) {
                BYTE    Buffer[1025];
                int     nBytes = (sizeof(Buffer) - 1);

                // read all of the data from the remote file, and write it the console
                while (FVSDK_ReadFile(pSession, Buffer, &nBytes) == FVSDK_YES) {

                    // add a NULL terminator to the string
                    Buffer[nBytes] = '\0';

                    // display the data from the file
                    puts(Buffer);

                    // reset the buffer size
                    nBytes = (sizeof(Buffer) - 1);
                } // while

                // close the remote file
                FVSDK_CloseFile(pSession);
            } // if
            else
                nRet = 3;

            // 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