Sample code for 30+ languages & platforms
Xbase++

SFTP ReadLink - Get the Target of a Symbolic Link on the Server

See more SFTP Examples

Demonstrates how to retrieve the target of a symbolic link on the SFTP server.

Note: This example requires Chilkat v9.5.0.71 or greater.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSftp
LOCAL cPath

nSuccess := 0

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

oSftp := CreateObject("Chilkat.SFtp")

//  Pass a domain or IP address..
nSuccess := oSftp:Connect("my-sftp-server.com", 22)
IF (nSuccess == 1)
    nSuccess := oSftp:AuthenticatePw("mySFtpLogin", "mySFtpPassword")
ENDIF

IF (nSuccess == 1)
    nSuccess := oSftp:InitializeSftp()
ENDIF

IF (nSuccess != 1)
    ? oSftp:LastErrorText
    oSftp:destroy()
    RETURN
ENDIF

//  In this example, the we already have a symbolic link named "sshd_config"
//  in our SSH/SFTP user account's HOME directory.  Get the target of this link:
cPath := oSftp:ReadLink("sshd_config")
IF (oSftp:LastMethodSuccess != 1)
    ? oSftp:LastErrorText
    oSftp:destroy()
    RETURN
ENDIF

? "symlink target path = " + cPath

//  Output is:  
//  symlink target path = /etc/ssh/sshd_config

oSftp:destroy()