Sample code for 30+ languages & platforms
C

Clear the SFTP Session Log

See more SFTP Examples

Demonstrates the Chilkat SFtp.ClearSessionLog method, which clears the in-memory text stored in the SessionLog property. It takes no arguments.

Background: With session logging enabled, the SessionLog accumulates a running record of the session's activity that is invaluable for diagnosing a failed transfer. Over a long-lived session that log grows unbounded, so clearing it frees memory — and, more usefully, lets you capture the log for one specific operation in isolation by clearing it just before and reading it just after.

Chilkat C Downloads

C
#include <C_CkSFtp.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkSFtp sftp;
    int port;
    const char *password;

    success = FALSE;

    //  Demonstrates the SFtp.ClearSessionLog method, which clears the in-memory text stored in the
    //  SessionLog property.  It takes no arguments.

    sftp = CkSFtp_Create();

    //  Connect, authenticate, and initialize the SFTP subsystem.
    port = 22;
    success = CkSFtp_Connect(sftp,"sftp.example.com",port);
    if (success == FALSE) {
        printf("%s\n",CkSFtp_lastErrorText(sftp));
        CkSFtp_Dispose(sftp);
        return;
    }

    //  Normally you would not hard-code the password in source.  You should instead obtain it
    //  from an interactive prompt, environment variable, or a secrets vault.
    password = "mySshPassword";

    success = CkSFtp_AuthenticatePw(sftp,"mySshLogin",password);
    if (success == FALSE) {
        printf("%s\n",CkSFtp_lastErrorText(sftp));
        CkSFtp_Dispose(sftp);
        return;
    }

    success = CkSFtp_InitializeSftp(sftp);
    if (success == FALSE) {
        printf("%s\n",CkSFtp_lastErrorText(sftp));
        CkSFtp_Dispose(sftp);
        return;
    }

    //  When KeepSessionLog is enabled, the SessionLog property accumulates a record of the session's
    //  activity, which is useful for debugging.
    CkSFtp_putKeepSessionLog(sftp,TRUE);

    //  ... perform operations ...

    //  Clear the accumulated log, for example before starting a new logical operation whose log you
    //  want to capture in isolation.
    CkSFtp_ClearSessionLog(sftp);
    printf("Session log cleared.\n");

    CkSFtp_Disconnect(sftp);


    CkSFtp_Dispose(sftp);

    }