Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to shebang-ify ftp and write small ftp scripts?

For example:

put *.gz

Any thoughts?


1 Answer 1

up vote 9 down vote accepted

Not with the ftp programs I've run into, as they expect a script on their standard input but a shebang would pass the script name on their command line.

You can use a here document to pass a script to ftp through a shell wrapper.

ftp <<EOF
put *.gz

Lftp accepts a script name passed as an argument.

#!/usr/bin/lftp -f
put *.gz

Ncftp comes with two tools ncftpget and ncftpput for simple batches of gets or puts.

Zsh includes an FTP module. Using a proper shell rather than a straight FTP script has the advantage that you can react to failures.

zmodload zsh/zftp
put *.gz

Of course there are plenty of other languages you could use: Perl, Python, Ruby, etc.

Another approach is to mount the FTP server as a directory, and then use cp (or rsync or other tools) to copy files. There are many FUSE filesystems for FTP access, principally CurlFtpFS and LftpFS.

Note that if you were planning to use authentication (likely if you're uploading), and you have control over the server, you'd be better off with SSH access. It's more secure and more flexible. To copy files over SSH, you can use scp or sftp, or rsync for efficient synchronization (if some of the files may already be there), or Unison (for bidirectional synchronization), or mount with SshFS.

Good answer, and to respond: The script I am trying to replace uses the "ftp <<EOF" method, which works and is fine, it just looks like the sort of pattern that shebangs attempt to abstract. –  user3454 May 4 '11 at 16:30

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .