NcFTP Guide

The NcFTP command line FTP client provides an efficient method of using the File Transfer Protocol. With NcFTP, you can run commands from the command line, which makes it ideal for scripting. This tutorial attempts to provide information regards the installation of NcFTP and the most commenly used commands.

Note: This guide assumes you are familiar with SSH and basic command line navigation. These instructions apply primarily to customers who have Virtual Private Servers or Dedicated servers. If you do not have root-level access you will not be able to make these changes.


Installation of NcFTP

CentOS 6.6

Install EPEL repository for CentOS 6:

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh epel-release-6*.rpm

After which you can install NcFTP:

yum install ncftp

CentOS 7

Install EPEL repository for CentOS 7:

wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-1.noarch.rpm
sudo rpm -Uvh epel-release-7*.rpm

After which you can install NCFTP:

yum install ncftp

Note: If you get a File Not Found error message when trying to download the EPEL Repository RPM, the version number might have changed. You can access the latest version of the repository package from the IUS Release Packages Page. Always make sure to select the correct architecture, i.e. i386 (32-bit) or x86_64 (64-bit).

When done you may disable the EPEL repository by going to the folder below. You will need to edit the epel.repo file.

nano /etc/yum.repos.d/epel.repo
enabled=0 (Repository is disabled)
enabled=1 (Repository is enabled)

Debian

apt-get install ncftp

Basic commands:

Start NcFTP

[user@server 11:16:59 ~]# ncftp
NcFTP 3.1.9 (Mar 24, 2005) by Mike Gleason (http://www.NcFTP.com/contact/).

Quit FTP

ncftp> quit
    221 Goodbye.
    [user@server 11:27:28 ~]#

Connect to remote server

To log in, you need to provide your username and password as well as your server hostname or ip address.

ncftp> open -u [username] -p [password] [hostname-or-ip-address]
Connecting to 10.20.30.40
ProFTPD 1.3.0 Server (Woktron - Backup FTP Server) [10.20.30.40]
Logging in...
[...]
Ensure to replace [username], [password] and [hostname-or-ip-address] with the correct values

The two steps above can also be combined into one single command:

ncftp -u [username] -p [password] [hostname-or-ip-address]

File Transfer

Download a file

ncftp> get file
    local: remote file: file
    200 PORT command successful
    150 Opening BINARY mode data connection for file (5242880 bytes)
    226 Transfer complete.
    5242880 bytes received in 0.45 secs (11407.6 kB/s)
    ftp>

By including the -R flag NCTFP enters Recursive mode. It copies whole directory trees.


In one single step:

ncftpget -R -T -v -u [username] -p [password] [hostname-or-ip-address] [/path/to/local/dir] [/path/to/remote/dir]

Upload a file

ncftp> put file
    local: remote file: file
    200 PORT command successful
    150 Opening BINARY mode data connection for file
    226 Transfer complete.
    5242880 bytes sent in 0.30 secs (16888.9 kB/s)
    ftp>

By including the -R flag NCTFP enters Recursive mode. It copies whole directory trees.


With one single command:

ncftpput -R -v -u [username] -p [password] [hostname-or-ip-address] [/path/to/remote/dir] [/path/to/local/dir]

Additional commands

Create directory

ncftp> mkdir backup
    257 "/backup" - Directory successfully created
    ftp>

Remove directory

ncftp> rmdir backup
    257 "/backup" - Directory successfully removed
    ftp>

Change directory

ftp> cd backup
    250 CWD command successful
    ftp>

List the contents of directory

ncftp> ls
    200 PORT command successful
    150 Opening ASCII mode data connection for file list
    -rw-r--r-- 1 Name_Of_Server users 5242880 Sep 24 09:24
    226 Transfer complete.
    ftp>

Custom ports

Use the -P portnumber option to specify a TCP port.

ncftpput -R -v -u [username] -p [password] -P 2121 [/path/to/remote/dir] [/path/to/local/dir]

Batch processing

1. setup batch process

A file transfer "job" is essentially a background task, which runs continually until the file transfer is complete. A job can be created and submitted with the ncftpget and ncftpput utilities; use the former for automated file downloads and the latter for automated file uploads. Here's an example:

ncftpget -bb -u [username] -p [password] [/path/to/remote/dir/targetfile.zip]
  
+ Spooled; writing locally as ./targetfile.zip.

This command creates a download job for the file targetfile.zip. The -bb parameter tells ncftpget to place the job in the background.


If it's a file upload you're after, use ncftpput instead, as in this next example:

ncftpput -bb -u [username] -p [password] [/path/to/remote/dir/targetfile.zip]

  + Spooled; sending remotely as secure/client203/targetfile.zip.

In this case, the access credentials must be followed by the remote host name, the remote directory name, and the local path to the file that is to be uploaded, respectively. Again, the -bb parameter tells ncftpput to place the job in the background.


2. start batch process

Once all the jobs have been submitted, begin processing them by invoking the ncftpbatch command, as follows:

ncftpbatch -d

This command will begin processing the jobs created in Step 1. Notice the -d option to the command; this runs ncftpbatch as a daemon, allowing you to continue working at the console while the jobs are being processed.

ncftpbatch will process all the submitted jobs automatically, with no intervention needed on your part. The program also includes intelligence to automatically re-try jobs that fail, either due to an error in connection or because the remote server is unavailable.


Optional Flags

  • -bb: background task
  • -d : run as daemon
  • -u : username
  • -p : password
  • -v : Verbose i.e. show upload progress
  • -P : TCP Port
  • -R : Recursive mode; copy whole directory trees.
  • -T : -T says not to try a tar download (it's never worked for me and results in the error "tar: This does not look like a tar archive" and "tar: Exiting with failure status due to previous errors". The actual files subsequently download just fine).


  • ncftp, installation, configuration, guide, tutorial, ftp
  • 15 Users Found This Useful
Was this answer helpful?

Related Articles

Installation of Directadmin on CentOS

In this guide I will be explaining how to install Direct Admin on a clean installation of CentOS...

Installation CSF Firewall on CentOS 5 and 6

The ConfigServer Security & Firewall is a popular open source Stateful Packet Inspection...

Installation of SpamAssassin on DirectAdmin

In this guide I will be explaining how to install and configure SpamAssasin on a Direct Admin...

Installation Rootkit Hunter (rkhunter) on CentOS

Rootkit Hunter (rkhunter) is a Unix-based tool that scans for rootkits, backdoors and possible...

Mounting Partitions in CentOS 5.x

This is a basic security tip that can be executed to help protect your system. This is not an...