Catalog / ncftp Cheatsheet

ncftp Cheatsheet

A comprehensive cheat sheet for ncftp, a versatile command-line FTP client with features like background processing, progress meters, and command chaining. This guide covers essential commands, usage examples, and tips for efficient file transfer.

Basic Usage

Connecting to Servers

ncftp

Starts ncftp in interactive mode.

ncftp <hostname>

Connects to the specified hostname using anonymous login.

ncftp -u <username> <hostname>

Connects to the specified hostname using the provided username.

ncftp -u <username>:<password> <hostname>

Connects using both username and password directly (less secure, use with caution).

open <hostname>

Connects to the specified hostname within the ncftp interactive mode.

open -u <username> <hostname>

Connects using a specific username within interactive mode, prompting for a password.

Basic File Operations

ls

Lists files in the current remote directory.

dir

Same as ls, lists files in the current remote directory.

pwd

Prints the current remote directory.

cd <directory>

Changes the current remote directory.

lcd <directory>

Changes the current local directory.

get <remote_file> [local_file]

Downloads a file from the remote server. Optionally, save it with a different name locally.

Transferring Files

get <remote_file> [local_file]

Downloads a file from the remote server. If local_file is not specified, it uses the same name.

put <local_file> [remote_file]

Uploads a file to the remote server. If remote_file is not specified, it uses the same name.

mget <remote_files>

Downloads multiple files from the remote server using wildcards.

mput <local_files>

Uploads multiple files to the remote server using wildcards.

ncftpget -R <bookmarkname> <remote_dir> <local_dir>

Recursively downloads an entire directory from the server specified by a bookmark.

ncftpput -R <bookmarkname> <local_dir> <remote_dir>

Recursively uploads an entire directory to the server specified by a bookmark.

Advanced Features

Background Processing

bgget <remote_file> [local_file]

Downloads a file in the background.

bgput <local_file> [remote_file]

Uploads a file in the background.

bkmkadd <bookmarkname>

Adds a bookmark for the current connection.

bkmk <bookmarkname>

Connects to a bookmarked site.

jobs

Lists background jobs.

kill <jobnumber>

Kills a background job.

Bookmarks

bookmark <bookmarkname>

Connects to a bookmarked server.

bkmkadd <bookmarkname>

Adds a bookmark for the current connection.

bkmkdel <bookmarkname>

Deletes a bookmark.

bkmklist

Lists all bookmarks.

open -b <bookmarkname>

Opens a connection using the specified bookmark.

bookmark bookmarkname

Bookmarks the current FTP location.

Resuming Transfers

get -z <remote_file> [local_file]

Attempts to resume a download.

put -z <local_file> [remote_file]

Attempts to resume an upload.

ncftpget -C <bookmark> <remote_file> <local_file>

Resume transfer based on a bookmark and specific files.

ncftpput -C <bookmark> <local_file> <remote_file>

Resume upload, specifying bookmarks and files.

Command Line Options

General Options

ncftp -d

Enables debugging mode.

ncftp -v

Verbose mode, shows more details.

ncftp -T <seconds>

Sets transfer timeout.

ncftp -u <username>

Specifies the username for login.

ncftp -p <port>

Specifies the port number to connect to.

ncftp -o <logfile>

Outputs ncftp’s log messages to the specified file.

Transfer Options

ncftp -C

Continues or resumes interrupted transfers.

ncftp -z

Tries to use the FXP protocol (server-to-server transfer).

ncftp -DD

Delete the source files after successful transfer.

ncftp -E

Force use of extended passive mode (EPSV).

ncftp -F

Force use of passive mode (PASV).

ncftp -a

Use ASCII transfer mode.

ncftpget and ncftpput Specific Options

ncftpget -R

Recursive retrieval of directories.

ncftpput -R

Recursive uploading of directories.

ncftpget -T <secs>

Transfer timeout in seconds.

ncftpput -S <secs>

Script timeout in seconds.

ncftpget -dd

Delete the source file after successfully downloading.

ncftpput -zz

Create missing directories.

Tips and Tricks

Efficient Transfers

Use bookmarks for frequently accessed servers to save time and avoid retyping credentials.

bkmkadd myserver
open -b myserver

For large directory transfers, use the -R option with ncftpget and ncftpput for recursive operations.

ncftpget -R myserver /remote/path /local/path

Leverage background transfers (bgget, bgput) to continue working while files are transferred.

bgget large_file.zip
jobs

Utilize the -C option to resume interrupted transfers, ensuring data integrity and saving bandwidth.

get -C interrupted_file.iso

Set transfer and script timeouts (-T, -S) to prevent stalled connections from blocking the client.

ncftp -T 30 server

Troubleshooting Common Issues

If experiencing connection problems, ensure the firewall allows FTP traffic on port 21 (control) and ports for data transfer.

Check firewall settings.

When transfers fail, verify that the remote directory exists and that you have the necessary permissions.

Use 'ls -l' to check permissions.

If passive mode is required, use the -F option or set use-pasv to yes in ~/.ncftp/config.

Set 'use-pasv yes' in config.

When encountering timeout issues, increase the transfer timeout using the -T option.

ncftp -T 60 server

To resolve issues with ASCII vs. binary transfers, force the transfer mode using -a (ASCII) or -b (binary).

get -b binary_file

Automation with Scripts

ncftp can be used in scripts for automated file transfers. Here’s a basic example:

#!/bin/bash
ncftp -u user:password ftp.example.com <<EOF
cd /remote/directory
get important_file.txt /local/path
bye
EOF

This script connects to an FTP server, navigates to a remote directory, downloads a file, and then exits.

For more complex tasks, you can chain commands using the -e option, executing commands sequentially. However, this is generally less reliable than using a script.

ncftp -u user:pass -e "cd /path; get file.txt local.txt; bye" host.com

When automating, ensure proper error handling. Use -S to set a script timeout, preventing indefinite hangs in case of errors.

ncftpput -S 60 -R bookmark /local/dir /remote/dir