PHP
Chilkat2 PHP
FTP Download File to a Stream
Demonstrates how to FTP download a file to a Chilkat stream.Chilkat PHP Downloads
<?php
use Chilkat2\Ftp2;
use Chilkat2\Stream;
// This example assumes the Chilkat FTP2 API to have been previously unlocked.
// See FTP2 Unlock Sample for sample code.
$ftp = new Ftp2();
$ftp->Hostname = 'my-ftp-server.com';
$ftp->Port = 21;
$ftp->Username = 'mFtpLogin';
$ftp->Password = 'myFtpPassword';
$ftp->AuthTls = true;
$ftp->Passive = true;
// Connect and login to the FTP server using TLS.
try {
$ftp->Connect();
// Move to the sub-directory (from the FTP user's home directory) where the file is located.
$ftp->ChangeRemoteDir('temp');
// Stream to this local file:
$streamObj = new Stream();
$streamObj->SinkFile = 'c:/temp/qa_output/penguins2.jpg';
$ftp->GetFileToStream('penguins2.jpg', $streamObj);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
$ftp->Disconnect();
echo "Success.\n";