<< Back to tutorials

Quick Storage API in Perl with the SFTP cloud storage

Published {$created} by Carsten Blum


Perl is a fantastic programming, or scripting language. In fact, when I started my first small software company, the very first project I landed was with a major danish bank, where I implemented risk management systems on AIX UNIX systems in Perl. :-) Great times!

Perl has long been a trusted language for scripting, sysadmin tasks, and automation. While modern ecosystems often lean toward Python or Go, Perl remains powerful for quick scripts that interact with servers and filesystems.

Instead of running your own FTP server, you can now leverage ftpGrid cloud FTP storage to use FTP and SFTP as a storage API. That means no servers to maintain, no certificates to renew, and full GDPR compliance out of the box.


In this tutorial, we’ll show how to generate a simple text file in Perl and upload it to ftpGrid using Net::SFTP::Foreign.


Before starting this tutorial, you need an account with ftpGrid, which is a simple process outlined in our getting started with FTP/SFTP guide. If your are in doubt if managed FTP/SFTP hosting is for you, you can read our guide to ftpGrid's managed hosting.



Requirements

  • Perl 5.x (available by default on most Linux/macOS systems)

  • CPAN module Net::SFTP::Foreign

  • An ftpGrid account with SFTP access


Prerequisite - install Net::SFTP::Foreign

On macOS with Homebrew

brew install cpanminus libssh2
sudo cpanm Net::SFTP::Foreign

#Alternative if not using sudo above:
cpanm --local-lib=~/perl5 local::lib
eval $(perl -I ~/perl5/lib/perl5 -Mlocal::lib)


On Ubuntu/Debian

sudo apt update
sudo apt install libnet-sftp-foreign-perl


With cpanminus (any platform)

curl -L https://cpanmin.us | perl - --sudo App::cpanminus
sudo cpanm Net::SFTP::Foreign



Step 1: Create a test file

echo "Hello from Perl and ftpGrid!" > hello.txt



Step 2: Example Perl script

Save as sftp_example.pl:

#!/usr/bin/perl 
use strict; 
use warnings; 
use Net::SFTP::Foreign;

my $host = "edge1.ftpgrid.com";
my $user = "PREFIX.username";
my $pass = "password";

print "Connecting to ftpGrid...\n";

my $sftp = Net::SFTP::Foreign->new(
    host => $host,
    user => $user,
    password => $pass,
    port => 22,
    autodie => 1
);


Ensure /uploads exists

my $dir = "/uploads";
unless ($sftp->stat($dir)) {
    $sftp->mkdir($dir) or die "Failed to create $dir: " . $sftp->error;
    print "Created remote directory $dir\n";
}


Upload file

my $local_file = "hello.txt";
my $remote_file = "$dir/hello.txt";

$sftp->put($local_file, $remote_file) or die "Upload failed: " . $sftp->error;
print "Uploaded $local_file to $remote_file\n";



Step 3: Run the script


Make it executable and run:

chmod +x sftp_example.pl 
./sftp_example.pl


Expected output:

Connecting to ftpGrid...
Created remote directory /uploads
Uploaded hello.txt to /uploads/hello.txt



Conclusion

With just a few lines of Perl, you’ve created a Quick Storage API that uploads files securely to ftpGrid’s cloud FTP storage.


This makes Perl a strong choice for:

  • Automating server backups

  • Uploading log files

  • Integrating FTP/SFTP storage into existing sysadmin workflows


Learn more on our FTP Cloud Storage page or follow the Quick Start guide to create your free account today.



Signup now
© 2025 ftpGrid

ftpGrid ApS
Branebjerg 24
DK-5471
Gamby
Denmark

Looking for an all-in-one time tracking, timesheet, and invoicing solution - visit our Devanux sister company Nureti at https://nureti.com.

Preview Devanux’s upcoming project Pictoguide – a visual support tool designed to bring structure and clarity to people with ASD.