Monday, June 30, 2008

FTP Using a One-Liner and Perl Script

A colleague of mine, Mahlon Anderson, wanted to revisit the FTP Using a Shell Script post.

Here is what he had to say...

Here is a creative way to put an FTP command on a single line. Why one line? The short story is I needed to do an ftp in a crontab without calling another script.

Three things to note:

1) I have only tested this with Solaris 8.
2) This works in the one true shell, Bourne shell.
3) If you have a "$" in your password, it might cause you problems.

Use this in a Perl script. (I didn’t have access to the CPAN FTP module)

# vi


$USER = “esoft”;
$echo = ‘echo “quote user ‘ . $USER. ‘\nquote pass ‘ . $PASSWORD .’\nbin\nlcd ‘ . $DIR . ‘\nmput $FILE\n”’;
@status = ‘$echo| ftp –nv $REMOTE‘;
print @status;

The FTP module is for doing FTP directly with Perl...basically system calls to the C library directly. With the right modules, you can do all that from Perl without having to resort to the back quotes.

Run via CLI

# ./


Hank Edley said...

Mahlon Anderson from West Central Illinois origins?

esofthub said...


I spoke to Mahlon a few hours ago about your comment. He was quite surprised when I mentioned your name. Small world and UNIX makes it smaller.

He wanted me to let you know he's going to respond soon.

Hank Edley said...

Thanks for passing it along .. if your working with Mahlon on a daily basis your working with one of the best.

esofthub said...

You're welcome Hank and I agree with you.

Anonymous said...

Think this guy is copying your contents "ditto"

chk out

Miral said...

Thanks for sharing ur knowledge