How to FTP multiple folders to another server using mput in Unix?

Command line FTP is pretty primitive.

You can't recursively send files/folders towards a remote site.

If you want to recreate a directory structure on the remote side the same as the local, you need to manually mkdir each path and use mput * to send everything in that directory to the remote side.

Two options to make this easier:

  1. Stop using the primitive FTP command (ncftp is a good alternative)

  2. Use tar to tar up the folders, send the file and extract on the far side.


I made a bash script:

#!/bin/bash
ftp_site=ftp.yoursite.net
username=my_user_name
passwd=my_password
remote=/path/to/remote/folder
folder=$1
cd /path/to/local/folder/$folder
pwd
ftp -in <<EOF
open $ftp_site
user $username $passwd
mkdir $remote/$folder
cd $remote/$folder
mput *
close
bye

and called it with

find . -type d -exec ./recursive-ftp.sh {} \;

seems to work.


This is not possible with the normal ftp program as mput does not use recursion. You could use ncftp and then call 'mput -r folder'.

Best wishes, Fabian