Linux ncftp Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the usage of the ncftp command-line FTP client on the Ubuntu 22.04 operating system. The lab covers the installation of ncftp, connecting to an FTP server, and managing files and directories on the server. We will start by installing the ncftp package, then demonstrate how to connect to an FTP server and perform various file management tasks, such as navigating directories and transferring files.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux(("`Linux`")) -.-> linux/RemoteAccessandNetworkingGroup(["`Remote Access and Networking`"]) linux/PackagesandSoftwaresGroup -.-> linux/apt("`Package Handling`") linux/FileandDirectoryManagementGroup -.-> linux/cd("`Directory Changing`") linux/FileandDirectoryManagementGroup -.-> linux/mkdir("`Directory Creating`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") linux/BasicFileOperationsGroup -.-> linux/rm("`File Removing`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") linux/RemoteAccessandNetworkingGroup -.-> linux/ftp("`File Transferring`") linux/RemoteAccessandNetworkingGroup -.-> linux/nc("`Networking Utility`") subgraph Lab Skills linux/apt -.-> lab-422834{{"`Linux ncftp Command with Practical Examples`"}} linux/cd -.-> lab-422834{{"`Linux ncftp Command with Practical Examples`"}} linux/mkdir -.-> lab-422834{{"`Linux ncftp Command with Practical Examples`"}} linux/ls -.-> lab-422834{{"`Linux ncftp Command with Practical Examples`"}} linux/rm -.-> lab-422834{{"`Linux ncftp Command with Practical Examples`"}} linux/sudo -.-> lab-422834{{"`Linux ncftp Command with Practical Examples`"}} linux/ftp -.-> lab-422834{{"`Linux ncftp Command with Practical Examples`"}} linux/nc -.-> lab-422834{{"`Linux ncftp Command with Practical Examples`"}} end

Install ncftp on Ubuntu 22.04

In this step, we will install the ncftp command-line FTP client on the Ubuntu 22.04 environment.

First, let's update the package index:

sudo apt-get update

Example output:

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done

Next, install the ncftp package using the following command:

sudo apt-get install -y ncftp

Example output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libevent-2.1-7 libncurses6 libreadline8 libssl3
Suggested packages:
  ncftp-doc
The following NEW packages will be installed:
  libevent-2.1-7 libncurses6 libreadline8 libssl3 ncftp
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,021 kB of archives.
After this operation, 3,415 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libncurses6 amd64 6.3-2 [84.0 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 libreadline8 amd64 8.1-1 [159 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy/main amd64 libevent-2.1-7 amd64 2.1.12-stable-1 [216 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy/main amd64 libssl3 amd64 3.0.2-0ubuntu1.6 [443 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy/universe amd64 ncftp amd64 3.2.6-1 [119 kB]
Fetched 1,021 kB in 1s (1,021 kB/s)
Selecting previously unselected package libncurses6:amd64.
(Reading database ... 14362 files and directories currently installed.)
Preparing to unpack .../libncurses6_6.3-2_amd64.deb ...
Unpacking libncurses6:amd64 (6.3-2) ...
Selecting previously unselected package libreadline8:amd64.
Preparing to unpack .../libreadline8_8.1-1_amd64.deb ...
Unpacking libreadline8:amd64 (8.1-1) ...
Selecting previously unselected package libevent-2.1-7:amd64.
Preparing to unpack .../libevent-2.1-7_2.1.12-stable-1_amd64.deb ...
Unpacking libevent-2.1-7:amd64 (2.1.12-stable-1) ...
Selecting previously unselected package libssl3:amd64.
Preparing to unpack .../libssl3_3.0.2-0ubuntu1.6_amd64.deb ...
Unpacking libssl3:amd64 (3.0.2-0ubuntu1.6) ...
Selecting previously unselected package ncftp.
Preparing to unpack .../ncftp_3.2.6-1_amd64.deb ...
Unpacking ncftp (3.2.6-1) ...
Setting up libncurses6:amd64 (6.3-2) ...
Setting up libreadline8:amd64 (8.1-1) ...
Setting up libevent-2.1-7:amd64 (2.1.12-stable-1) ...
Setting up libssl3:amd64 (3.0.2-0ubuntu1.6) ...
Setting up ncftp (3.2.6-1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...

The ncftp package is now installed on your Ubuntu 22.04 environment.

Connect to an FTP Server Using ncftp

In this step, we will learn how to connect to an FTP server using the ncftp command-line client.

First, let's create a directory to store our FTP connection details:

mkdir ~/project/ftp_config

Next, we'll create a configuration file to store the FTP server connection details:

nano ~/project/ftp_config/ftp.cfg

Add the following content to the file, replacing the placeholders with your actual FTP server details:

host=ftp.example.com
user=myusername
pass=mypassword

Save and close the file.

Now, let's connect to the FTP server using the ncftp command:

ncftp -u myusername -p mypassword ftp.example.com

Example output:

ncftp>

You should now be connected to the FTP server. You can use the following commands to navigate and manage files on the server:

  • ls - List files and directories on the FTP server
  • cd <directory> - Change the current directory on the FTP server
  • get <file> - Download a file from the FTP server
  • put <file> - Upload a file to the FTP server
  • quit - Disconnect from the FTP server

To exit the ncftp client, type quit and press Enter.

Manage Files and Directories on the FTP Server

In this step, we will learn how to manage files and directories on the FTP server using the ncftp command-line client.

First, let's connect to the FTP server using the ncftp command:

ncftp -u myusername -p mypassword ftp.example.com

Example output:

ncftp>

Now, let's explore the available commands to manage files and directories:

  1. List files and directories on the FTP server:
ncftp> ls

Example output:

drwxr-xr-x   2 user     group         4096 Apr 12 12:34 documents
-rw-r--r--   1 user     group           24 Apr 12 12:34 example.txt
  1. Change the current directory on the FTP server:
ncftp> cd documents
  1. Upload a file to the FTP server:
ncftp> put ~/project/local_file.txt
  1. Download a file from the FTP server:
ncftp> get remote_file.txt
  1. Create a new directory on the FTP server:
ncftp> mkdir new_directory
  1. Delete a file on the FTP server:
ncftp> rm example.txt
  1. To exit the ncftp client, type quit and press Enter.
ncftp> quit

Remember to replace the file and directory names with your actual FTP server details.

Summary

In this lab, we learned how to install the ncftp command-line FTP client on Ubuntu 22.04, connect to an FTP server using ncftp, and manage files and directories on the FTP server. We started by updating the package index and then installed the ncftp package. Next, we connected to an FTP server using the ncftp command and explored various commands to navigate the FTP server, upload and download files, and manage directories.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like