Sample code for 30+ languages & platforms
PowerShell

FTP Upload / Download to a BinData Object

Demonstrates how to FTP upload the contents of a BinData object, and FTP downloads to the a BinData object.

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

# This example assumes Chilkat Ftp2 to have been previously unlocked.
# See Unlock Ftp2 for sample code.

$ftp = New-Object Chilkat.Ftp2

$ftp.Hostname = "www.my-ftp-server.com"
$ftp.Username = "mFtpLogin"
$ftp.Password = "myFtpPassword"

# Connect to the FTP server.
$success = $ftp.ConnectOnly()
if ($success -ne $true) {
    $($ftp.LastErrorText)
    exit
}

# Authenticate with the FTP server.
$success = $ftp.LoginAfterConnectOnly()
if ($success -ne $true) {
    $($ftp.LastErrorText)
    exit
}

$bdA = New-Object Chilkat.BinData
$bdA.LoadFile("qa_data/jpg/penguins.jpg")

# Upload the contents of bdA to the FTP server.
$remoteFilename = "penguins.jpg"
$success = $ftp.PutFileBd($bdA,$remoteFilename)
if ($success -ne $true) {
    $($ftp.LastErrorText)
    exit
}

# Download...
$bdB = New-Object Chilkat.BinData
$success = $ftp.GetFileBd($remoteFilename,$bdB)
if ($success -ne $true) {
    $($ftp.LastErrorText)
    exit
}

# Verify that bdA and bdB have the exact same contents.
$("size of bdA: " + $bdA.NumBytes)
if ($bdA.ContentsEqual($bdB) -eq $true) {
    $("Contents are equal. Success.")
}
else {
    $("Contents are NOT equal.  Failed.")
}

$ftp.Disconnect()