Making FTP more bearable with modern command-line tools

Summary

On Hackaday, Al Williams shows that FTP on the command line is far more pleasant today than its reputation suggests. The usual ftp on Debian and openSUSE is already the improved tnftp, and NcFTP adds bookmarks, recursive transfers, background jobs and dedicated commands for scripts. Unencrypted FTP remains insecure and belongs only where you do not control the other end.

What today's ftp already does

On openSUSE Tumbleweed and in Debian Bookworm and Trixie, /usr/bin/ftp is tnftp, the portable version of the NetBSD client. It offers line editing, history, file name completion, passive FTP and IPv6, and even fetches HTTP, HTTPS and file: URLs directly, for example with ftp https://example.com/file.tar.gz.

Where NcFTP makes the difference

NcFTP stores a target including its directory as a bookmark (bookmark oldstuff, later ncftp oldstuff) and caches directory listings, which saves a lot of time over slow links. get -R and put -R transfer whole directories, NcFTP resumes interrupted transfers by itself, and bgget queues large files in its own spooler.

For scripts the package includes ncftpget, ncftpput and ncftpls. A call such as ncftpput ftp.example.com /incoming widget.bin replaces the fragile approach of feeding ftp through a here document with a login from .netrc.

Ideas

  • The default ftp of many distributions has long been a modern client.
  • tnftp also fetches HTTP and HTTPS URLs.
  • Bookmarks turn recurring FTP targets into named resources.
  • Cached directory listings save waiting time on slow connections.
  • Recursive and resumable transfers remove manual work.
  • Dedicated commands for scripts are more robust than remote-controlled interactive programs.

Insights

  • Old protocols stay as long as the other side demands them; good tools defuse them.
  • A command that expresses exactly one intent is easier to check than a session inside a script.

Quotes

  • ordinary FTP is not secure. (Al Williams)

Facts

  • Debian Trixie ships tnftp 20230507 and ncftp 3.2.7.
  • ncftpget, ncftpput and ncftpls work without an interactive command interpreter.
  • With bgget, NcFTP hands transfers to its own spooler.
  • With tnftp an interrupted transfer has to be resumed explicitly.

References

Remarks

  • The article does not cover FTP with TLS (FTPS). bk99.de itself is published via FTPS, using curl and individual transfers, because mirroring tools were unreliable against this server.

Recommendations

  • Use ncftpput and ncftpget instead of here documents when a script has to speak FTP.
  • Require encryption on servers with TLS, for example with curl --ssl-reqd.
  • Replace FTP with SFTP or rsync over SSH as soon as you control both ends.

Read the original article

Search the Web Archive

Found a mistake or have something to add? Get in touch.