Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Sftp
integer li_Port
string ls_Password

li_Success = 0

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

loo_Sftp = create oleobject
li_rc = loo_Sftp.ConnectToNewObject("Chilkat.SFtp")
if li_rc < 0 then
    destroy loo_Sftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Connect, authenticate, and initialize the SFTP subsystem.
li_Port = 22
li_Success = loo_Sftp.Connect("sftp.example.com",li_Port)
if li_Success = 0 then
    Write-Debug loo_Sftp.LastErrorText
    destroy loo_Sftp
    return
end if

//  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.
ls_Password = "mySshPassword"

li_Success = loo_Sftp.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
    Write-Debug loo_Sftp.LastErrorText
    destroy loo_Sftp
    return
end if

li_Success = loo_Sftp.InitializeSftp()
if li_Success = 0 then
    Write-Debug loo_Sftp.LastErrorText
    destroy loo_Sftp
    return
end if

//  When KeepSessionLog is enabled, the SessionLog property accumulates a record of the session's
//  activity, which is useful for debugging.
loo_Sftp.KeepSessionLog = 1

//  ... perform operations ...

//  Clear the accumulated log, for example before starting a new logical operation whose log you
//  want to capture in isolation.
loo_Sftp.ClearSessionLog()
Write-Debug "Session log cleared."

loo_Sftp.Disconnect()


destroy loo_Sftp