Xbase++
Xbase++
AWS Transfer for SFTP (Amazon S3)
See more SFTP Examples
Once you've setup your AWS Transfer for SFTP in the AWS Console, interacting with it is no different than any other SSH/SFTP server. AWS will provide a private key in PEM format. It is used for authentication (instead of a password).Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oSftp
LOCAL cDomain
LOCAL nPort
LOCAL oSshKey
LOCAL cKeyText
LOCAL cRemoteFilePath
LOCAL cLocalFilePath
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oSftp := CreateObject("Chilkat.SFtp")
// Connect to the AWS SFTP server.
// Change the domain to your value.
cDomain := "s-123456df999999fab.server.transfer.eu-west-2.amazonaws.com"
nPort := 22
nSuccess := oSftp:Connect(cDomain, nPort)
IF (nSuccess == 0)
? oSftp:LastErrorText
oSftp:destroy()
RETURN
ENDIF
// Load your AWS SFTP private key PEM file..
oSshKey := CreateObject("Chilkat.SshKey")
cKeyText := oSshKey:LoadText("qa_data/pem/s3_sftp_privateKey.pem")
IF (oSshKey:LastMethodSuccess != 1)
? oSshKey:LastErrorText
oSftp:destroy()
oSshKey:destroy()
RETURN
ENDIF
nSuccess := oSshKey:FromOpenSshPrivateKey(cKeyText)
IF (nSuccess == 0)
? oSshKey:LastErrorText
oSftp:destroy()
oSshKey:destroy()
RETURN
ENDIF
// Authenticate with the SSH server using the private key.
nSuccess := oSftp:AuthenticatePk("myUsername", oSshKey)
IF (nSuccess == 0)
? oSftp:LastErrorText
oSftp:destroy()
oSshKey:destroy()
RETURN
ENDIF
// After authenticating, the SFTP subsystem must be initialized:
nSuccess := oSftp:InitializeSftp()
IF (nSuccess == 0)
? oSftp:LastErrorText
oSftp:destroy()
oSshKey:destroy()
RETURN
ENDIF
// Upload from the local file to the SSH server.
// Important -- the remote filepath is the 1st argument,
// the local filepath is the 2nd argument;
cRemoteFilePath := "hamlet.xml"
cLocalFilePath := "c:/temp/hamlet.xml"
nSuccess := oSftp:UploadFileByName(cRemoteFilePath, cLocalFilePath)
IF (nSuccess == 0)
? oSftp:LastErrorText
oSftp:destroy()
oSshKey:destroy()
RETURN
ENDIF
? "Success."
oSftp:destroy()
oSshKey:destroy()