<< Back


Connecting to an FTP server is relatively straightforward. Before continuing with this document, please read the Getting Started Overview section.

Connecting With a User ID and Password

After initializing the FVSDK_Session structure, as outlined in the Getting Started Overview section, set the FVSDK_Session elements for pszServer, pszUserID, and pszPassword. The following is an example showing how to connect, then login to a server.

#include <windows.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.yourserver.com";

        // set the user id to use during the connection
        pSession->pszUserID = "youruserid";

        // set the password to use during the connection
        pSession->pszPassword = "yourpassword";

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

            // ... perform some operations ...

            // disconnect from the server
            FVSDK_Disconnect(pSession);
        } // if
        else
            nRet = 2;

        // close and release the session
        FVSDK_FreeSession(pSession);
    } // if
    else
        nRet = 1;

    // exit from our application, 0 == success, otherwise an error
    return (nRet);
} // main

Connecting Anonymously

Some public archive servers allow anonymous or public access to the server. The server usually still requires login, however a special user ID is used (usually "anonymous"). To connect to one of these servers, set pszServer to the server name and connect. The default User ID is already set to "anonymous". The following is an example showing how to connect to a server anonymously.

#include <windows.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";

        // pszUserID is already set to "anonymous" by default, but we'll explicitly set it for demonstrative purposes
        pSession->pszUserID = "anonymous";

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

            // ... perform some operations ...

            // disconnect from the server
            FVSDK_Disconnect(pSession);
        } // if
        else
            nRet = 2;

        // close and release the session
        FVSDK_FreeSession(pSession);
    } // if
    else
        nRet = 1;

    // exit from our application, 0 == success, otherwise an error
    return (nRet);
} // main