Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
FTP Upload Encrypted and CompressedDownload: Chilkat .NET Assemblies Compress and encrypt a file, and upload it to an FTP server. Then do the reverse (download, decrypt, inflate). Dim ftp As New Chilkat.Ftp2() Dim success As Boolean ' Any string unlocks the component for the 1st 30-days. success = ftp.UnlockComponent("Anything for 30-day trial") If (success <> true) Then MsgBox(ftp.LastErrorText) Exit Sub End If Dim crypt As New Chilkat.Crypt2() ' Any string unlocks the component for the 1st 30-days. success = crypt.UnlockComponent("Anything for 30-day trial") If (success <> true) Then MsgBox(crypt.LastErrorText) Exit Sub End If ftp.Hostname = "www.example-code.com" ftp.Username = "***" ftp.Password = "***" ' Connect and login to the FTP server. success = ftp.Connect() If (success <> true) Then MsgBox(ftp.LastErrorText) Exit Sub End If ' Change to the remote directory where the file will be uploaded. success = ftp.ChangeRemoteDir("junk") If (success <> true) Then MsgBox(ftp.LastErrorText) Exit Sub End If ' Read the file into memory. Dim fileData As New ByteData() fileData = crypt.ReadFile("hamlet.xml") If (fileData Is Nothing ) Then MsgBox(crypt.LastErrorText) Exit Sub End If Dim compressedData As New ByteData() compressedData = crypt.CompressBytes(fileData) ' Use 128-bit AES encryption, in CBC mode. crypt.CryptAlgorithm = "aes" crypt.CipherMode = "cbc" crypt.KeyLength = 128 crypt.SetEncodedKey("0123456789ABCDEF","ascii") crypt.SetEncodedIV("0123456789ABCDEF","ascii") Dim encryptedData As New ByteData() encryptedData = crypt.EncryptBytes(compressedData) ' Upload from a byte array. Dim remoteFilename As String remoteFilename = "hamlet.dat" success = ftp.PutFileFromBinaryData(remoteFilename,encryptedData) If (success <> true) Then MsgBox(ftp.LastErrorText) Exit Sub End If ' Now do the reverse: Dim encryptedData2 As New ByteData() encryptedData2 = ftp.GetRemoteFileBinaryData(remoteFilename) If (encryptedData2 Is Nothing ) Then MsgBox(ftp.LastErrorText) Exit Sub End If ' Decrypt: Dim decryptedData As New ByteData() decryptedData = crypt.DecryptBytes(encryptedData2) ' Inflate: Dim inflatedData As New ByteData() inflatedData = crypt.InflateBytes(decryptedData) ' Save the decrypted/inflated data to a file. success = crypt.WriteFile("hamlet2.xml",inflatedData) If (success <> true) Then MsgBox(crypt.LastErrorText) Exit Sub End If ftp.Disconnect() MsgBox("File Uploaded and Downloaded!") |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.