Batch transfer local files to an ftp server
ftp-upload [any-switch]... {[repeatable-switch]... file...}...
ftp-upload is used to send local files to an \s-1FTP\s0 server. It isn't interactive, it's meant to be used from scripts. It is disciplined about its exit value and it doesn't output informational messages by default.
There are two kinds of switches. Initial switches have to appear before any filenames, they affect the session as a whole. Repeatable switches can appear interspersed with the file names, they affect the transfer of the files which appear after them on the command line.
\$1
These have to be used before any file names listed on the command line.
Turn debugging on.
Show the usage message and die.
Don't complain or set a failure exit code just because the \s-1QUIT\s0 command fails. This can be necessary because some servers, in blatant disregard of \s-1RFC\s0 959, close the command channel when you send them an \s-1ABOR\s0 command.
Print informational messages to stdout.
Show the version number and exit. These also have to be used before any file names listed on the command line. They specify the information used to set up the \s-1FTP\s0 connection.
This specifies the account to be used when logging into the remote system. This is distinct from the user name used to log in. Few systems need this. There is no default.
Specify the host to which to connect. There is no default, you have to specify this switch.
Force the use of passive (\s-1PASV\s0) transfers. Passive transfers are required with some firewall configurations, but if you have such you'd do better to configure Net::FTP so that it knows when to use them (see Net::Config). If you need to use passive transfers with certain (broken) servers, however, this switch is your best bet. Alternatively, you can set $FTP_PASSIVE to 1 in the environment (see Net::FTP).
This gives the password which will be used to login. The default is your email address. Note that you should not specify a real (secret) password this way, as on most systems anybody on the machine can see the arguments you pass to your commands. Use one of other password-setting switches instead.
This tells ftp-upload to read the password from standard input. No prompt will be printed, and a single line will be read. Most people will use this switch to specify the password. Eg,
echo 3x9sjJJh | ftp-upload -sh $host -u $user $file
Using echo this way is safe where the --password switch isn't if the echo command is built in to the shell.
This is like --password-stdin except that it reads the password from the file descriptor numbered fd. ftp-upload -h $host -u $user --password-fd=3 3<$pw_file $file
Specify the user name to use when logging in. The default is \*(C`anonymous\*(C'. These switches can be used anywhere on the command line (except after the last file name). They affect the transfer of files listed after them.
Normally a file is transferred using the same name it has locally. If you use this switch the next file transferred will be called remote-name on the other host instead. ftp-upload --host $host --as index.htm index.html
Perform transfers in \s-1ASCII\s0 mode.
Perform transfers in binary mode. This is the default.
Change directory to dir on the \s-1FTP\s0 server before continuing. You can use this multiple times between files, ftp-upload will chdir once for each time you specify it. Using \*(C`..\*(C' as the dir will cause an \s-1FTP\s0 \*(C`CDUP\*(C' to be done rather than a \*(C`CWD\*(C'.
Normally uploaded files go into the current directory on the remote host, even when the local file name given contains slashes. Eg, if you say ftp-upload -h $host /etc/motd ftp-upload will upload the file as motd, not /etc/motd. This differs from how the standard ftp program works, and it also differs with how ftp-upload worked before version 1.3. If you specify --full-path, you'll get the other behavior. A request to upload dir/file will tell the server to store dir/file rather than file. When you use --as the --full-path setting doesn't matter. --full-path only tells the program what name to use when it's choosing the name.
Disable --full-path. This is the default.
Try to get a remote directory listing of files after transferring them. I say \*(L"try\*(R" because there's no guaranteed way to do this with the \s-1FTP\s0 protocol. The command I run is \*(C`LIST file\*(C'. This will generally work if file doesn't contain any special characters.
Disable the --ls behavior.
Transfer files directly, don't do anything special to try to ensure that they don't appear under their real names on the remote machine until the transfer is finished. Each file is transferred with a single simple \*(C`STOR\*(C'. This is the default.
Transfer files to the remote machine using a temporary name, then rename them when the transfer finishes. This won't work if the remote server doesn't give a recognizable response to the \*(C`STOU\*(C' command. If the server's response to \*(C`STOU\*(C' isn't recognized by Net::FTP but is reasonable, Graham Barr might be willing to change Net::FTP to recognize it. If you like you can send the \*(C`--debug\*(C' output to me and I'll coordinate such requests.
Transfer files to dir on the remote host, then rename them when the transfer is complete. This is safer than --tmp-samedir because it doesn't use \*(C`STOU\*(C' and so it works with more servers. ftp-upload -h $host --tmp-dir incoming $file
Transfer files to \*(C`sprintf(fmt, file base name)\*(C', then rename them when the transfer is complete. Like --tmp-dir, this is safer than --tmp-samedir because it doesn't use \*(C`STOU\*(C' and so it works with more servers. ftp-upload -h $host --tmp-format tmp.%s $file
Roderick Schertler <[email protected]>