#!/usr/bin/perl -w # # $Id: //websites/unixwiz/unixwiz.net/webroot/tools/ftpput.txt#1 $ # # written by : Stephen J. Friedl # Software Consultant # Tustin, California USA # # This very simple program is a kind of inverse to wget for ftp: it # *puts* files to a remote FTP server and returns an exit code that # reports accurately success or failure. # # All the parameters are given on the command line (no .netrc support) # # COMMAND LINE PARAMS # -------------------- # # --help Display a short help listing # # --server=S Use "S" as the remote FTP server to connect to. We don't # need the leading "ftp://" part (but it's stripped off if # provided). This is REQUIRED. # # --user=U Use "U" as the login name as required by the remote machine. # In the absense of one, "anonymous" is used. # # --pass=P Use "P" for the password on the remote machine. # # --dir=D Change to directory D on the remote system before doing # any transfers. If not provided, the directory is not # changed before doing a transfer. # # --passive Use passive (PASV) mode for this transfer, which is # required by some servers and some firewalls. If not # specified, active mode is used. # # --hash Print a hash mark ("#") every 1024 bytes during the transfer # to watch it run. # # --verbose Show the name of each file being sent. This is much less info # than the --debug option # use strict; use warnings; use Net::FTP; my $Version = "unixwiz.net ftpput - version 1.0 (2003/05/09)"; my $server = undef; my $user = undef; my $pass = undef; my $dir = undef; my $debug = 0; my $hash = 0; my $passive = 0; my $binary = 0; my $ascii = 0; my $verbose = 0; my @FILES = (); foreach ( @ARGV ) { if ( m/^--help/i ) { print STDERR <new( $server, %FTPARGS) ) ) { die "ERROR: cannot connect to FTP server $server\n"; } if ( not $ftp->login($user, $pass) ) { die "ERROR: cannot login to $server with user $user\n"; } if ( $dir ) { $ftp->cwd($dir) or die "ERROR: cannot cwd($dir)\n"; } if ( $binary ) { $ftp->binary() or die "ERROR: cannot set binary mode\n"; } if ( $ascii ) { $ftp->ascii() or die "ERROR: cannot set ASCII mode\n"; } foreach my $file ( @FILES ) { print "--> put $file\n" if $verbose; if ( not $ftp->put($file) ) { die "ERROR: cannot send $file\n"; } print " (sent OK)\n" if $verbose; } $ftp->quit or die "ERROR: cannot quit FTP transfer\n"; exit 0;