Visual FoxPro
Visual FoxPro
Flush an SFTP File to Stable Storage (Fsync)
See more SFTP Examples
Demonstrates the Chilkat SFtp.Fsync method, which requests that the server flush pending data for an open file to stable storage. The only argument is the handle. It uses the OpenSSH fsync@openssh.com extension and succeeds only when the server supports it.
Background: A successful write does not guarantee the data has reached disk — it may still sit in the server's write cache, where a crash or power loss would lose it.
Fsync forces it to durable storage, which matters for transactional or journal-style files where a committed record must survive a failure. Because it relies on a non-standard OpenSSH extension, expect it to fail against servers that do not implement it, and treat that as a capability check rather than a hard error where appropriate.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loSftp
LOCAL lnPort
LOCAL lcPassword
LOCAL lcHandle
lnSuccess = 0
* Demonstrates the SFtp.Fsync method, which requests that the server flush pending data for an
* open file to stable storage. The only argument is the handle.
loSftp = CreateObject('Chilkat.SFtp')
* Connect, authenticate, and initialize the SFTP subsystem.
lnPort = 22
lnSuccess = loSftp.Connect("sftp.example.com",lnPort)
IF (lnSuccess = 0) THEN
? loSftp.LastErrorText
RELEASE loSftp
CANCEL
ENDIF
* Normally you would not hard-code the password in source. You should instead obtain it
* from an interactive prompt, environment variable, or a secrets vault.
lcPassword = "mySshPassword"
lnSuccess = loSftp.AuthenticatePw("mySshLogin",lcPassword)
IF (lnSuccess = 0) THEN
? loSftp.LastErrorText
RELEASE loSftp
CANCEL
ENDIF
lnSuccess = loSftp.InitializeSftp()
IF (lnSuccess = 0) THEN
? loSftp.LastErrorText
RELEASE loSftp
CANCEL
ENDIF
lcHandle = loSftp.OpenFile("subdir/journal.log","writeOnly","openOrCreate,appendData")
IF (loSftp.LastMethodSuccess = 0) THEN
? loSftp.LastErrorText
RELEASE loSftp
CANCEL
ENDIF
* Write a critical record.
lnSuccess = loSftp.WriteFileText(lcHandle,"utf-8","2026-07-23 transaction committed" + CHR(10))
IF (lnSuccess = 0) THEN
? loSftp.LastErrorText
RELEASE loSftp
CANCEL
ENDIF
* Ask the server to flush the data to durable storage before continuing. Fsync uses the
* OpenSSH fsync@openssh.com extension and succeeds only when the server supports it.
lnSuccess = loSftp.Fsync(lcHandle)
IF (lnSuccess = 0) THEN
? loSftp.LastErrorText
RELEASE loSftp
CANCEL
ENDIF
lnSuccess = loSftp.CloseHandle(lcHandle)
IF (lnSuccess = 0) THEN
? loSftp.LastErrorText
RELEASE loSftp
CANCEL
ENDIF
? "Data flushed to stable storage."
loSftp.Disconnect()
RELEASE loSftp