We've long used the wget to fetch
data from a remote web or ftp server, but for customer projects we've
needed to do the opposite: send a file to a remote FTP server. In
the past we've done it either piping a response file to FTP or building
a front end with Expect. Neither of this is really the right answer,
as they don't handle error conditions terribly well.
Having done this one too many times and gotten sick of it, we decided
to write a perl program that talks to the remote server directly using
the Net::FTP module. This made the whole thing easy and reliable. The
program is not very large at all - just a front end for the real
workhorse provided by Net::FTP.
Overview
This program takes a handful of options (with only --server being
required), plus a list of files to send to the other end. The options
can be in any order, and at least one filename is required (it won't
read from the standard input).
$ ftpput --server=ftp.unixwiz.net --verbose --user=steve --pass=yahright file1 file2
--> put file1
(sent OK)
--> put file2
(sent OK)
- --help
- Show a brief help listing to the standard error and exit.
- --debug
- Enable Net::FTP package debugging. This is quite verbose
and the output format is not always very helpful. For everyday
use, try --verbose instead.
- --verbose
- Print the name of each file being transferred. This isk
much less "noisy" than --debug.
- --server=SVR
- Connect to the FTP server SVR. This can be a hostname or an
IP address. This parameter is required.
- --user=U
- Login as the user U, or use anonymous if not given.
- --pass=PASS
- Provide password PASS to the FTP server during
login. This defaults to "-anonymous@" if not given, but this
is not very meaningful if this is not an anonymous connection.
Sorry that this password is provided in cleartext on the command
line: this has been entirely suitable for all of our applications.
- --dir=DIR
- Change to directory DIR on the remote system before
sending any files. All the files provided on the command line
have only the final part of the pathname considered - the directory
path of the source files are not considered in any way.
- --passive
- Use passive FTP mode instead of active. This may be
required by an Internet firewall in between your station and
the remote FTP server.
- --ascii
- Send the file in ASCII mode, which attempts to convert the
local line termination (CR/LF, newline, CR) to that used by the remote
server. This is only useful for text files.
- --binary
- Use binary ("image") mode when sending the file to the
remote system. This performs no conversions of any kind on the data.
- --hash
- Print a hash mark (#) every 1024 bytes during
the transfer to show progress.
Bugs
- The password is provided on the command line, and it can usually
be seen by anybody running the "ps" command. This is not secure.
- There is no way to put files to multiple directories on the
remote server - all the files go into the same directory. We don't
want to make the target directory depend on the source path, but
we may look for a way to do this.
- This program has no proxy support (yet).
Download
- ftpput.txt (perl program, but ".txt" for easy downloading)
Revision History
- v1.0 (2003/05/09) - Initial release