Linux / Unix ncftp: Upload Directory Tree To Remote FTP Server Recursively

by on April 27, 2005 · 8 comments· LAST UPDATED October 28, 2012

in , ,

When you host your web site remotely and and the ftp server is the only way to upload all files including subdirectroies. You need to use special file transfer program such as ncftpget or ncftpput for recursive remote ftp server uploading and downloading purpose. Ncftp is considered as an improved FTP client. Ncftp's improvements include support for command line editing, command histories, recursive gets/puts, automatic anonymous logins, and much more.

Install ncftp client

Type the following apt-get command under Debian / Ubuntu Linux to install ncftp client, run:
$ sudo apt-get install ncftp
Sample outputs:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  ncftp
0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
Need to get 588 kB of archives.
After this operation, 1,307 kB of additional disk space will be used.
Get:1 http://debian.osuosl.org/debian/ squeeze/main ncftp amd64 2:3.2.4-1 [588 kB]
Fetched 588 kB in 2s (199 kB/s)
Selecting previously deselected package ncftp.
(Reading database ... 274906 files and directories currently installed.)
Unpacking ncftp (from .../ncftp_2%3a3.2.4-1_amd64.deb) ...
Processing triggers for menu ...
Processing triggers for man-db ...
Setting up ncftp (2:3.2.4-1) ...
update-alternatives: using /usr/bin/ncftp3 to provide /usr/bin/ncftp (ncftp) in auto mode.
Processing triggers for menu ...

If you are RHEL / CentOS / Fedora Linux user, type the following yum command to install ncftp client (first turn on EPEL repo):
# yum install ncftp

Syntax and examples

The syntax is as follows:

 
ncftpput ftp-host-name /path/to/remote/dir /path/to/local/dir
ncftpput -options ftp-host-name /path/to/remote/dir /path/to/local/dir
 

Try the ncftpput client command as follows:

 
ncftpput -R -v -u "username" ftp.nixcraft.biz /nixcraft/forum /tmp/phpbb
 

Where,

  • -u "username" : Ftp server username
  • -v : Verbose i.e. show upload progress
  • -R : Recursive mode; copy whole directory trees.
  • ftp.nixcraft.biz : Remote ftp server (use FQDN or IP).
  • /nixcraft/forum : Remote ftp server directory where all files and subdirectories will be uploaded.
  • /tmp/phpbb : Local directory (or list of files) to upload remote ftp server directory /nixcraft/forum

You can pass the password with -p option:

 
ncftpput -R -v -u "username" -p "passwordHere" ftp.nixcraft.biz /nixcraft/forum /tmp/phpbb
 

You can use port number 2021 instead of the default FTP service port # 21 as follows:

 
ncftpput -R -v -u "username" -p "passwordHere" -P 2021 ftp.nixcraft.biz /nixcraft/forum /tmp/phpbb
 
See also
  • See ftptreeupload.bash script to copy all files and subdirectories recursively and upload them to remote FTP server (copy local all directories/tree to remote ftp server).
  • ncftpput client can be downloaded from http://www.ncftp.com/ncftp/ and works with FreeBSD, Solaris and all most all UNIX like variant.
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 8 comments… read them below or add one }

1 SamTronik May 10, 2010 at 4:03 pm

Thanks for this – saved me an age.

Just for those who dont work it out themselves, you can not copy and paste the command line as the – (minus/dash) sign is not the correct type. You will need to replace them with a dash from your keyboard. Something to do with the way the web formats them I guess.

Reply

2 happy halloween October 30, 2010 at 3:20 pm

Jupp, saved my day uploading 300GB of data to a new repository with only ftp available…
Works fine with symbolic link in the filesystem.

Reply

3 vamsi krishna December 17, 2010 at 6:18 pm

+1 for SamTronik, just type manually.
-R -v -u and so on..

Reply

4 Avin December 9, 2011 at 5:28 am

Can we also provide password in same command ?
If yes..How to do that ?

I want to use this in my script.

Reply

5 Lernen January 10, 2012 at 2:59 pm

Hi, I am trying to upload a wordpress folder which contains some sub folders… but your command uploads everything in the root folder and is not creating any folders. …

Reply

6 Alan July 1, 2013 at 8:02 pm

nixCraft, always helping me to solve problems!
Thanks a lot!!!

Reply

7 James December 5, 2013 at 3:38 am

This doesn’t work when executed from Crontab or when the script is double-clicked in the File browser.

Reply

8 Dhavid Claudius Gunawan August 28, 2014 at 12:54 pm

This post from 2005 really saved my day. Thank you 9 years old post.

Reply

Leave a Comment

Tagged as: , , , ,

Previous post:

Next post: