PHP
Chilkat2 PHP
FTP Upload / Download to StringBuilder
Demonstrate how to upload from a Chilkat StringBuilder object, and download into a StringBuilder object.Chilkat PHP Downloads
<?php
use Chilkat2\Ftp2;
use Chilkat2\StringBuilder;
// 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();
$sbA = new StringBuilder();
$sbA->LoadFile('qa_data/hamlet.xml', 'utf-8');
// Upload the contents of sbA to the FTP server.
$bIncludeBOM = false;
$remoteFilename = 'hamletFromSb.xml';
$ftp->PutFileSb($sbA, 'utf-8', $bIncludeBOM, $remoteFilename);
// Download...
$sbB = new StringBuilder();
$ftp->GetFileSb($remoteFilename, 'utf-8', $sbB);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Verify that sbA and sbB have the exact same contents.
echo 'size of sbA: ', $sbA->Length, "\n";
$bCaseSensitive = true;
if ($sbA->ContentsEqualSb($sbB, $bCaseSensitive)) {
echo "Contents are equal. Success.\n";
} else {
echo "Contents are NOT equal. Failed.\n";
}
$ftp->Disconnect();