PureBasic
PureBasic
FTP Upload / Download to StringBuilder
Demonstrate how to upload from a Chilkat StringBuilder object, and download into a StringBuilder object.Chilkat PureBasic Downloads
IncludeFile "CkFtp2.pb"
IncludeFile "CkStringBuilder.pb"
Procedure ChilkatExample()
success.i = 0
; This example assumes Chilkat Ftp2 to have been previously unlocked.
; See Unlock Ftp2 for sample code.
ftp.i = CkFtp2::ckCreate()
If ftp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkFtp2::setCkHostname(ftp, "www.my-ftp-server.com")
CkFtp2::setCkUsername(ftp, "mFtpLogin")
CkFtp2::setCkPassword(ftp, "myFtpPassword")
; Connect to the FTP server.
success = CkFtp2::ckConnectOnly(ftp)
If success <> 1
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
; Authenticate with the FTP server.
success = CkFtp2::ckLoginAfterConnectOnly(ftp)
If success <> 1
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
ProcedureReturn
EndIf
sbA.i = CkStringBuilder::ckCreate()
If sbA.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkStringBuilder::ckLoadFile(sbA,"qa_data/hamlet.xml","utf-8")
; Upload the contents of sbA to the FTP server.
bIncludeBOM.i = 0
remoteFilename.s = "hamletFromSb.xml"
success = CkFtp2::ckPutFileSb(ftp,sbA,"utf-8",bIncludeBOM,remoteFilename)
If success <> 1
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
CkStringBuilder::ckDispose(sbA)
ProcedureReturn
EndIf
; Download...
sbB.i = CkStringBuilder::ckCreate()
If sbB.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkFtp2::ckGetFileSb(ftp,remoteFilename,"utf-8",sbB)
If success <> 1
Debug CkFtp2::ckLastErrorText(ftp)
CkFtp2::ckDispose(ftp)
CkStringBuilder::ckDispose(sbA)
CkStringBuilder::ckDispose(sbB)
ProcedureReturn
EndIf
; Verify that sbA and sbB have the exact same contents.
Debug "size of sbA: " + Str(CkStringBuilder::ckLength(sbA))
bCaseSensitive.i = 1
If CkStringBuilder::ckContentsEqualSb(sbA,sbB,bCaseSensitive) = 1
Debug "Contents are equal. Success."
Else
Debug "Contents are NOT equal. Failed."
EndIf
CkFtp2::ckDisconnect(ftp)
CkFtp2::ckDispose(ftp)
CkStringBuilder::ckDispose(sbA)
CkStringBuilder::ckDispose(sbB)
ProcedureReturn
EndProcedure