Sample code for 30+ languages & platforms
Xbase++

SFTP Upload and Download to a BinData Object

See more SFTP Examples

Demonstrates how to SFTP upload from a BinData object, and download into a BinData object.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSftp
LOCAL nPort
LOCAL oBdA
LOCAL cRemotePath
LOCAL oBdB

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

oBdA := CreateObject("Chilkat.BinData")
oBdA:LoadFile("qa_data/jpg/penguins.jpg")

//  Upload the contents of bdA to the SSH/SFTP server.
cRemotePath := "sftpTesting/penguins.jpg"
nSuccess := oSftp:UploadBd(oBdA, cRemotePath)
IF (nSuccess != 1)
    ? oSftp:LastErrorText
    oSftp:destroy()
    oBdA:destroy()
    RETURN
ENDIF

//  Download the file..
oBdB := CreateObject("Chilkat.BinData")
nSuccess := oSftp:DownloadBd(cRemotePath, oBdB)
IF (nSuccess != 1)
    ? oSftp:LastErrorText
    oSftp:destroy()
    oBdA:destroy()
    oBdB:destroy()
    RETURN
ENDIF

//  Verify that bdA and bdB have the exact same contents.
? "size of bdA: " + Str(oBdA:NumBytes)
IF (oBdA:ContentsEqual(oBdB) == 1)
    ? "Contents are equal. Success."
ELSE
    ? "Contents are NOT equal.  Failed."
ENDIF

oSftp:Disconnect()

oSftp:destroy()
oBdA:destroy()
oBdB:destroy()