Xbase++
Xbase++
SFTP Upload and Download to a StringBuilder Object
See more SFTP Examples
Demonstrates how to SFTP upload from a Chilkat StringBuilder object, and download into a StringBuilder object.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oSftp
LOCAL nPort
LOCAL oSbA
LOCAL nBIncludeBOM
LOCAL cRemotePath
LOCAL oSbB
LOCAL nBCaseSensitive
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oSftp := CreateObject("Chilkat.SFtp")
// Set some timeouts, in milliseconds:
oSftp:ConnectTimeoutMs := 5000
oSftp:IdleTimeoutMs := 10000
// Connect to the SSH server and then authenticate.
nPort := 22
nSuccess := oSftp:Connect("MY-SSH-SERVER-DOMAIN-OR-IP", nPort)
IF (nSuccess == 1)
nSuccess := oSftp:AuthenticatePw("MY-SSH-LOGIN", "MY-SSH-PASSWORD")
IF (nSuccess == 1)
nSuccess := oSftp:InitializeSftp()
ENDIF
ENDIF
IF (nSuccess != 1)
? oSftp:LastErrorText
oSftp:destroy()
RETURN
ENDIF
oSbA := CreateObject("Chilkat.StringBuilder")
oSbA:LoadFile("qa_data/hamlet.xml", "utf-8")
// Upload the contents of sbA to the SSH/SFTP server.
nBIncludeBOM := 0
cRemotePath := "sftpTesting/hamlet.xml"
nSuccess := oSftp:UploadSb(oSbA, cRemotePath, "utf-8", nBIncludeBOM)
IF (nSuccess != 1)
? oSftp:LastErrorText
oSftp:destroy()
oSbA:destroy()
RETURN
ENDIF
// Download the file..
oSbB := CreateObject("Chilkat.StringBuilder")
nSuccess := oSftp:DownloadSb(cRemotePath, "utf-8", oSbB)
IF (nSuccess != 1)
? oSftp:LastErrorText
oSftp:destroy()
oSbA:destroy()
oSbB:destroy()
RETURN
ENDIF
// Verify that sbA and sbB have the exact same contents.
? "size of sbA: " + Str(oSbA:Length)
nBCaseSensitive := 1
IF (oSbA:ContentsEqualSb(oSbB, nBCaseSensitive) == 1)
? "Contents are equal. Success."
ELSE
? "Contents are NOT equal. Failed."
ENDIF
oSftp:Disconnect()
oSftp:destroy()
oSbA:destroy()
oSbB:destroy()