#!/usr/bin/perl -w
# ftp.pl - an ftp session

use strict;
use Net::FTP;

my $host = shift || 'server.onsight.com';
my $user = shift || $ENV{USER};
die "no user!" unless $user;

my $dir = '/tmp';
my $file = 'perl5.005_51.tar.gz';
my($pass, $command);

my $ftp = Net::FTP->new($host);
die "could not connect: $!" unless $ftp;

print "Enter your password: ";
system "stty -echo";
chop($pass = <STDIN>);
system "stty echo";

print "\nBefore\n", '-' x 40, "\n"; 
print `/bin/ls *.gz`; 
print '-' x 40, "\n";

$ftp->login($user,$pass) 
           or die "login failed: $!";
$ftp->cwd($dir)          
           or die "cwd failed: $!";
$ftp->get($file)         
           or die "get failed: $!";
$ftp->quit               
           or die "quit failed: $!";

print "\nAfter\n", '-' x 40, "\n"; 
print `/bin/ls *.gz`; 
print '-' x 40, "\n";
