VB.NET
VB.NET
Upload Text to an FTP Server (StringBuilder)
See more FTP Examples
Demonstrates the Chilkat Ftp2.PutFileSb method, which encodes the text in a StringBuilder and uploads it to a remote path. The arguments are the StringBuilder, the charset, whether to include a byte-order mark, and the remote file path.
Background: The text-oriented upload: assemble a document — CSV, config, JSON — in a
StringBuilder and the method handles encoding as it writes. The charset governs the bytes actually stored, and the byte-order-mark flag is useful when a consuming Windows application expects a BOM.Chilkat VB.NET Downloads
Dim success As Boolean = False
' Demonstrates the Ftp2.PutFileSb method, which encodes the text in a StringBuilder and uploads
' it to a remote path. The 1st argument is the StringBuilder, the 2nd is the charset, the 3rd
' selects whether a byte-order mark is included, and the 4th is the remote file path.
Dim ftp As New Chilkat.Ftp2
ftp.Hostname = "ftp.example.com"
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.
ftp.Password = "myPassword"
success = ftp.Connect()
If (success = False) Then
Debug.WriteLine(ftp.LastErrorText)
Exit Sub
End If
' Build the text to upload.
Dim sb As New Chilkat.StringBuilder
sb.Append("name,quantity" & vbLf)
sb.Append("widgets,42" & vbLf)
' Upload as UTF-8 without a byte-order mark.
Dim includeBom As Boolean = False
success = ftp.PutFileSb(sb,"utf-8",includeBom,"public_html/inventory.csv")
If (success = False) Then
Debug.WriteLine(ftp.LastErrorText)
Exit Sub
End If
Debug.WriteLine("Uploaded text file.")
success = ftp.Disconnect()
If (success = False) Then
Debug.WriteLine(ftp.LastErrorText)
Exit Sub
End If