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

Posted on in Categories Howto, Linux, UNIX last updated October 28, 2012

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 for recursive remote ftp server uploading 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 more.

Linux: Download all file from ftp server recursively

Posted on in Categories FreeBSD, Gentoo Linux, Howto, Linux, Linux desktop, RedHat/Fedora Linux, Shell scripting, Solaris, Suse Linux, Sys admin, Tips, Ubuntu Linux, UNIX last updated September 26, 2007

You can use ncftpget command to download entire ftp directory and sub directories from remote ftp server. Let us say you would like to download /www-data directory and all subdirectories inside this one from server. You need to use ncftpget command.

Install ncftp client

ncftp client software can be downloaded from and works with FreeBSD, Solaris and all most all UNIX variant. You can also run command as follows to install ncftp:
$ sudo apt-get install ncftp

FTP get directory recursively

ncftpget is Internet file transfer program for scripts and advance usage. You need to use command as follows:
$ ncftpget –R –v –u "ftpuser" /home/vivek/backup /www-data

  • -R : Copy all subdirectories and files (recursive)
  • -v : Verbose i.e. display download activity and progess
  • -u “USERNAME” : FTP server username, if skipped ncftpget will try anonymous username
  • : Ftp server name
  • /home/vivek/backup : Download everything to this directory
  • /www-data : Remote ftp directory you wish to copy

If you get an error which read as follows:

tar: End of archive volume 1 reached
tar: Sorry, unable to determine archive format.
Could not read directory listing data: Connection reset by peer

Then add –T option to ncftpget command:

$ ncftpget –T –R –v –u "ftpuser" /home/vivek/backup /www-data


  • -T : Do not try to use TAR mode with Recursive mode

Linux > How to encrypting a files for particular user (recipients aka your trusted friend)

Posted on in Categories News last updated April 8, 2005

1) In order to encrypt a file for your friend or recipients you need to obtains his/hers GnuPG public key. It can be obtained why an email, keyserver or even usb pen device. Then import the friends public using following command:
$ gpg –import

2) Once key added to your GnuPG key ring, it is time to encrypt the file(s) using your private key and the recipient’s public key so that only your particular friend or recipients can decrypt it:
gpg -e -r Public_key_ID file

For example to decrypt, file myfin.rec.txt:
$ gpg -e -r A560159A myfin.rec.txt
$ gpg -e -r vivek myfin.rec.txt
$ gpg –a -e -r vivek myfin.rec.txt

gpg: 54CCC70D: There is no indication that this key really belongs to the owner
2048g/54CCC70D 2005-03-18 “Vivek G Gite (My keys for all friends) ”
Primary key fingerprint: 00BD 76AB A6EC 574B F3F7 4BC5 EAF2 7147 A560 159A
Subkey fingerprint: 8D5E 4B3E 17D9 F491 CA04 D4B7 1BF4 E16C 54CC C70D

It is NOT certain that the key belongs to the person named
in the user ID. If you *really* know what you are doing,
you may answer the next question with yes

Use this key anyway? yes

-e : Encrypt data.
-r : Encrypt for user id name. You can specify the user id (vivek) or Public_key_id
(A560159A). Note use gpg –list-public-key to obtain the Public_key_ids.
-a : Create ASCII armored output so that file can be send via an email

3) Use the email to send the file to your friend/ recipients so that only he/she can decrypt it.

4) When your file reached to desire user/friend/recipients s/he need to run simply gpg command on it:
$ gpg myfin.rec.txt.asc

gpg myfin.rec.txt.asc

You need a passphrase to unlock the secret key for
user: “Vivek G Gite (My keys for all friends) ”
2048-bit ELG-E key, ID 54CCC70D, created 2005-03-18 (main key ID A560159A)
Enter passphrase: MYPASS

gpg: encrypted with 2048-bit ELG-E key, ID 54CCC70D, created 2005-03-18
“Vivek G Gite (My keys for all friends) ”

5) If some other person steals your file and tries to decrypt it using gpg:
$ gpg myfin.rec.txt.asc
gpg: encrypted with ELG-E key, ID 54CCC70D
gpg: decryption failed: secret key not available

It should fail with above error message and that is the whole point to use the GnuPG :)

Linux : How to export public key for others/friends or your recipients

Posted on in Categories News last updated April 8, 2005

1) Login to your shell account

2) Use –export option to export your public key in text file
$ gpg –export –a > my.key
$ gpg –export -a | mail -s “My key” [email protected]

-a –armor : Create ASCII armored output.
–export : Export the key for sharing

First command write output to file my.key and second directly sends an email to your friend. Once my.key delivered to friend, he/she need to import it using the following command (aka adding keys to your keyring):
$ gpg –import my.key

Linux create your own GnuPG private and public key

Posted on in Categories Debian Linux, Gentoo Linux, GNU/Open source, Howto, Linux, RedHat/Fedora Linux, Security, Tips, Ubuntu Linux, UNIX last updated February 10, 2007

GNU gpg is encryption and signing tool.

The GNU Privacy Guard (GnuPG or GPG) is a free software replacement for the PGP suite of cryptographic software.

GnuPG encrypts messages using asymmetric keypairs individually generated by GnuPG users. The resulting public keys can be exchanged with other users in a variety of ways, such as Internet key servers. They must always be exchanged carefully to prevent identity spoofing by corrupting public key ↔ ‘owner’ identity correspondences. It is also possible to add a cryptographic digital signature to a message, so the message integrity and sender can be verified, if a particular correspondence relied upon has not been corrupted.

How do I create my own GnuPG private and public key

1) Login to your shell account

2) Use gpg command to create the keys
$ gpg --gen-key

gpg (GnuPG) 1.4.1; Copyright (C) 2005 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

gpg: directory `/home/vivek/.gnupg' created
gpg: new configuration file `/home/vivek/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/vivek/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/vivek/.gnupg/secring.gpg' created
gpg: keyring `/home/vivek/.gnupg/pubring.gpg' created
Please select what kind of key you want:
   (1) DSA and Elgamal (default)
   (2) DSA (sign only)
   (5) RSA (sign only)
Your selection? Press [Enter] Key
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) Press [Enter] Key
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
        = key expires in n days
      w = key expires in n weeks
      m = key expires in n months
      y = key expires in n years
Key is valid for? (0) Press [Enter] Key
Key does not expire at all
Is this correct? (y/N) y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) "

Real name: Vivek Gite
Email address: [email protected]
Comment:[Enter] key
You selected this USER-ID:
    "Vivek Gite "

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.

Enter passphrase: [Enter password twice]
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: /home/vivek/.gnupg/trustdb.gpg: trustdb created
gpg: key 8E19F126 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
pub   1024D/8E19F126 2007-02-10
      Key fingerprint = A7AF E25D 3E8D 6946 37CC  8CCE 12C4 8DC1 8E19 F126
uid                  Vivek Gite 
sub   2048g/032824B9 2007-02-10

3) Now keys generated, you can list your own key using:
$ gpg -K
$ gpg --list-keys

pub   1024D/CA7A8402 2007-02-10
uid                  Vivek Gite 
sub   2048g/0A7B4F93 2007-02-10

Let us try to understand the line pub 1024D/CA7A8402 2007-02-10:

  • pub : Public key
  • 1024D : The number of bits in the key
  • CA7A8402 : The key ID
  • 2007-02-10 : The date of key creation
  • Vivek Gite : The user real name
  • <[email protected]> : The email id

Most important is the key ID i.e. CA7A8402. Make sure you use powerful passphrase to protect keys and not the easy one.

4) To list secret key, type the command:
$ gpg --list-secret-keys

sec   1024D/CA7A8402 2007-02-10
uid                  Vivek Gite 
ssb   2048g/0A7B4F93 2007-02-10