Sample code for 30+ languages & platforms
Perl

FTP Upload with Progress Event Callbacks

See more FTP Examples

FTP upload with progress event callbacks.

Chilkat Perl Downloads

Perl
use strict;
use warnings;
use Chilkat2;

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

my $ftp = Chilkat2::Ftp2->new;
$ftp->on(
    PercentDone => sub {
        my ($percentDone) = @_;
        print 'Percent Done: ', $percentDone, "\n";
        return 0;   # return 1 to abort the method in progress
    },
    ProgressInfo => sub {
        my ($name, $value) = @_;
        print $name, ': ', $value, "\n";
    }
);

$ftp->Hostname('ftp.someFtpServer.com');
$ftp->Username('my_ftp_username');
$ftp->Password('my_ftp_password');

# Connect and login to the FTP server.
my $success = $ftp->Connect();
if (!$success) {
    print $ftp->LastErrorText, "\n";
    exit;
}

# Change to the remote directory where the file will be uploaded.
$success = $ftp->ChangeRemoteDir('junk');
if (!$success) {
    print $ftp->LastErrorText, "\n";
    exit;
}

# Upload a file.
my $localPath = 'c:/temp/hamlet.xml';
my $remoteFilename = 'hamlet.xml';

$success = $ftp->PutFile($localPath, $remoteFilename);
if (!$success) {
    print $ftp->LastErrorText, "\n";
    exit;
}

$success = $ftp->Disconnect();

print "File Uploaded!\n";