Sample code for 30+ languages & platforms
PowerBuilder

Set the FTP Password from a SecureString

See more FTP Examples

Demonstrates the Chilkat Ftp2.SetSecurePassword method, which sets the login password from a SecureString. The only argument is the SecureString. It is equivalent to setting the Password property but avoids holding the password as an ordinary immutable string.

Background: An ordinary string password can linger in memory (and in memory dumps) because strings are immutable and copied freely. A SecureString keeps the value encrypted under a session key and clears it deterministically, reducing that exposure — a sensible upgrade for a credential the process holds for the life of the connection. Populate it from a runtime source rather than a hard-coded literal.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp
string ls_Password
oleobject loo_SecurePassword

li_Success = 0

//  Demonstrates the Ftp2.SetSecurePassword method, which sets the login password from a
//  SecureString.  The only argument is the SecureString.  This avoids holding the password as an
//  ordinary immutable string.

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
    destroy loo_Ftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Ftp.Hostname = "ftp.example.com"
loo_Ftp.Username = "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.
ls_Password = "myPassword"

//  Place the password into a SecureString, which keeps it encrypted in memory.
loo_SecurePassword = create oleobject
li_rc = loo_SecurePassword.ConnectToNewObject("Chilkat.SecureString")

loo_SecurePassword.Append(ls_Password)

//  Setting the secure password is equivalent to setting the Password property, but more
//  protective.
li_Success = loo_Ftp.SetSecurePassword(loo_SecurePassword)
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    destroy loo_SecurePassword
    return
end if

li_Success = loo_Ftp.Connect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    destroy loo_SecurePassword
    return
end if

Write-Debug "Connected using a secure password."

li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    destroy loo_SecurePassword
    return
end if



destroy loo_Ftp
destroy loo_SecurePassword