Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#CC++MFCDelphiFoxProJavaPerlPythonRubySQL ServerVBScript

PHP ActiveX Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3


 

 

 

 

 

 

 

 

Asynchronous FTP Download

The Chilkat FTP component supports asynchronous uploads and downloads. This examples demonstrates doing a download in a background thread. The download is started by calling AsyncGetFileStart. While the download is in progress, your program may do other tasks. You may periodically check the AsyncFinished property to determine when the transfer is finished. The example below provides the remainder of the details.

Download 32-bit Chilkat FTP2 ActiveX (.msi)

Download All 32-bit Chilkat ActiveX Components (.zip)

Download All 64-bit Chilkat ActiveX Components (.zip)

<?php

$ftp = new COM("Chilkat.Ftp2");

//  Any string unlocks the component for the 1st 30-days.
$success = $ftp->UnlockComponent('Anything for 30-day trial');
if ($success != true) {
    print $ftp->lastErrorText() . "\n";
    exit;
}

$ftp->Hostname = 'www.secureftp-test.com';
$ftp->Username = 'test';
$ftp->Password = 'test';

//  Connect and login to the FTP server.
$success = $ftp->Connect();
if ($success != true) {
    print $ftp->lastErrorText() . "\n";
    exit;
}

$localFilename = 'hamlet.xml';
$remoteFilename = 'hamlet.xml';

//  Begin the download in a background thread.
//  Only 1 background upload or download may be active at any time.
//  (per instance of an FTP object)
$success = $ftp->AsyncGetFileStart($remoteFilename,$localFilename);
if ($success != true) {
    print $ftp->lastErrorText() . "\n";
    exit;
}

//  The application is now free to do anything else
//  while the file is downloading.
//  For this example, we'll simply sleep and periodically
//  check to see if the transfer if finished.  While checking
//  however, we'll report on the progress in both number
//  of bytes tranferred and performance in bytes/second.
while ($ftp->AsyncFinished != true) {

    print $ftp->AsyncBytesReceived . ' bytes received' . "\n";
    print $ftp->DownloadRate . ' bytes per second' . "\n";

    //  Sleep 1 second.
    $ftp->SleepMs(1000);

}

//  Did the download succeed?
if ($ftp->AsyncSuccess == true) {
    print 'File Downloaded!' . "\n";
}
else {
    //  The error information for asynchronous ops
    //  is in AsyncLog as opposed to LastErrorText
    print $ftp->asyncLog() . "\n";
}

$ftp->Disconnect();
?>

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.