PHP
Chilkat2 PHP
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 PHP Downloads
<?php
use Chilkat2\BinData;
use Chilkat2\Ftp2;
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
$ftp = new Ftp2();
$ftp->Hostname = 'www.my-ftp-server.com';
$ftp->Username = 'mFtpLogin';
$ftp->Password = 'myFtpPassword';
// Connect to the FTP server.
try {
$ftp->ConnectOnly();
// Authenticate with the FTP server.
$ftp->LoginAfterConnectOnly();
$bdA = new BinData();
$bdA->LoadFile('qa_data/jpg/penguins.jpg');
// Upload the contents of bdA to the FTP server.
$remoteFilename = 'penguins.jpg';
$ftp->PutFileBd($bdA, $remoteFilename);
// Download...
$bdB = new BinData();
$ftp->GetFileBd($remoteFilename, $bdB);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Verify that bdA and bdB have the exact same contents.
echo 'size of bdA: ', $bdA->NumBytes, "\n";
if ($bdA->ContentsEqual($bdB)) {
echo "Contents are equal. Success.\n";
} else {
echo "Contents are NOT equal. Failed.\n";
}
$ftp->Disconnect();