PureBasic
PureBasic
Download an FTP File as ANSI Text
See more FTP Examples
Demonstrates the Chilkat Ftp2.GetRemoteFileTextData method, which downloads a remote file and returns its contents decoded using the ANSI character encoding. The only argument is the remote filename.
Background: A convenience for reading a remote text file straight into a string, assuming ANSI encoding. "ANSI" is platform-dependent (the Windows code page on Windows), so this is only reliable for plain ASCII or content you know is in that encoding — for UTF-8 or any explicitly known charset, use
GetRemoteFileTextC and name the encoding.Chilkat PureBasic Downloads
IncludeFile "CkFtp2.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the Ftp2.GetRemoteFileTextData method, which downloads a remote file and returns
; its contents decoded using the ANSI character encoding. The only argument is the remote
; filename.
ftp.i = CkFtp2::ckCreate()
If ftp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkFtp2::setCkHostname(ftp, "ftp.example.com")
CkFtp2::setCkUsername(ftp, "myFtpLogin")
; 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.
CkFtp2::setCkPassword(ftp, "myPassword")
success = CkFtp2::ckConnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
; Use this for ANSI-encoded text. For UTF-8 or another known encoding, use GetRemoteFileTextC.
fileText.s = CkFtp2::ckGetRemoteFileTextData(ftp,"public_html/readme.txt")
If CkFtp2::ckLastMethodSuccess(ftp) = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
Debug fileText
success = CkFtp2::ckDisconnect(ftp)
If success = 0
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndProcedure