Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSftp
LOCAL lnPort
LOCAL loSbA
LOCAL lnBIncludeBOM
LOCAL lcRemotePath
LOCAL loSbB
LOCAL lnBCaseSensitive

lnSuccess = 0

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loSftp = CreateObject('Chilkat.SFtp')

* Set some timeouts, in milliseconds:
loSftp.ConnectTimeoutMs = 5000
loSftp.IdleTimeoutMs = 10000

* Connect to the SSH server and then authenticate.
lnPort = 22
lnSuccess = loSftp.Connect("MY-SSH-SERVER-DOMAIN-OR-IP",lnPort)
IF (lnSuccess = 1) THEN
    lnSuccess = loSftp.AuthenticatePw("MY-SSH-LOGIN","MY-SSH-PASSWORD")
    IF (lnSuccess = 1) THEN
        lnSuccess = loSftp.InitializeSftp()
    ENDIF

ENDIF

IF (lnSuccess <> 1) THEN
    ? loSftp.LastErrorText
    RELEASE loSftp
    CANCEL
ENDIF

loSbA = CreateObject('Chilkat.StringBuilder')
loSbA.LoadFile("qa_data/hamlet.xml","utf-8")

* Upload the contents of sbA to the SSH/SFTP server.
lnBIncludeBOM = 0
lcRemotePath = "sftpTesting/hamlet.xml"
lnSuccess = loSftp.UploadSb(loSbA,lcRemotePath,"utf-8",lnBIncludeBOM)
IF (lnSuccess <> 1) THEN
    ? loSftp.LastErrorText
    RELEASE loSftp
    RELEASE loSbA
    CANCEL
ENDIF

* Download the file..
loSbB = CreateObject('Chilkat.StringBuilder')
lnSuccess = loSftp.DownloadSb(lcRemotePath,"utf-8",loSbB)
IF (lnSuccess <> 1) THEN
    ? loSftp.LastErrorText
    RELEASE loSftp
    RELEASE loSbA
    RELEASE loSbB
    CANCEL
ENDIF

* Verify that sbA and sbB have the exact same contents.
? "size of sbA: " + STR(loSbA.Length)
lnBCaseSensitive = 1
IF (loSbA.ContentsEqualSb(loSbB,lnBCaseSensitive) = 1) THEN
    ? "Contents are equal. Success."
ELSE
    ? "Contents are NOT equal.  Failed."
ENDIF

loSftp.Disconnect()

RELEASE loSftp
RELEASE loSbA
RELEASE loSbB