Automating Backups with Wput Scripts

Wput: A Beginner’s Guide to Remote File TransfersRemote file transfer is a routine—but crucial—task for system administrators, developers, and power users. Wput is a lightweight, command-line tool designed specifically for uploading files to remote servers using FTP and its secure variants. This guide introduces Wput, shows how to install and use it, explains common options and workflows, and offers troubleshooting tips and best practices for safe, efficient transfers.


What is Wput?

Wput is a small, command-line utility for uploading files and directories to FTP servers. It emulates the feel of wget (which downloads files) but in reverse: wput sends local files to remote FTP or FTPS servers. Its simplicity, scripting-friendly behavior, and minimal dependencies make it attractive for automation, simple backups, and integration into deployment pipelines.

Key points

  • Purpose: Upload files to FTP/FTPS servers from the command line.
  • Protocol support: FTP and FTPS (explicit TLS).
  • Designed for: Automation, scripts, lightweight uploads.

Why use Wput?

Wput fills a niche: when you need a straightforward, scriptable uploader without the overhead or complexity of full-featured FTP clients or GUI tools. Compared to GUI FTP clients, wput is easily automated. Compared to heavier CLI tools (like lftp), wput’s learning curve is very small.

Common use cases:

  • Uploading build artifacts in CI scripts.
  • Simple backups to a remote FTP server.
  • One-off uploads from servers or headless environments.
  • Integrating into cron jobs or small deployment scripts.

Installing Wput

Wput is typically available in Linux distributions’ package repositories and can be built from source. Examples:

  • Debian/Ubuntu:

    sudo apt update sudo apt install wput 
  • Fedora:

    sudo dnf install wput 
  • Arch Linux (AUR or community repo depending on availability):

    sudo pacman -S wput 
  • From source:

    1. Download source (from the project’s site or repository).
    2. Extract, then:
      
      ./configure make sudo make install 

If your distribution doesn’t provide a package, building from source is straightforward but requires basic build tools (autoconf, make, gcc).


Basic usage

The simplest invocation uploads a single file:

wput localfile ftp://username:[email protected]/remote/path/ 

If the server permits anonymous access, omit credentials:

wput myfile.zip ftp://ftp.example.com/pub/uploads/ 

Wput will open an FTP connection, transfer the file, and report progress and status in the terminal.


Uploading directories and recursive transfers

Wput supports recursive uploads using the -r option:

wput -r mydir ftp://user:[email protected]/remote/dir/ 

This sends the directory structure and files under mydir to the specified remote directory, creating subdirectories as needed.


Securing uploads: FTPS

If your server supports explicit TLS (FTPS), use the ftps:// scheme:

wput file.txt ftps://user:[email protected]/secure/path/ 

FTPS encrypts the control and data channels, preventing credentials and file contents from being exposed on the network. Note: wput’s FTPS support depends on how it was compiled and what SSL/TLS libraries are available on the system.


Useful options

  • -r — recursive upload (directories).
  • --limit-rate=RATE — cap upload bandwidth (useful on shared hosts). Example: --limit-rate=100k.
  • -v — increase verbosity (more logging).
  • -q — quiet mode (minimal output).
  • --delete — remove local files after successful upload (use with caution).
  • --continue — resume partially uploaded files when supported by server.
  • --ask-password — prompt for password interactively instead of exposing it in the command line.

Example with options:

wput -r --limit-rate=200k --continue localdir ftps://[email protected]/backup/ 

This recursively uploads localdir, limits bandwidth to 200 KB/s, and attempts to resume partial uploads.


Authentication best practices

Avoid embedding plaintext passwords in command lines or scripts visible to other users or process lists. Prefer one of these safer approaches:

  • Use --ask-password to type the password at runtime:
    
    wput --ask-password file ftp://[email protected]/path/ 
  • Store credentials in a restricted-permission script or config file readable only by the deploying user (chmod 600).
  • Use FTPS to encrypt credentials in transit.
  • For automated systems, consider using dedicated service accounts with restricted privileges and short-lived credentials if possible.

Scripting examples

Cron job to upload nightly build artifacts:

#!/bin/sh ARCHIVE="/var/builds/latest.tar.gz" REMOTE="ftps://deployuser:[email protected]/backups/" wput --continue "$ARCHIVE" "$REMOTE" 

Atomic upload with temporary filename (to avoid partial-file readers):

wput localfile ftp://user:[email protected]/tmp/.localfile.part && wput --delete localfile ftp://user:[email protected]/final/localfile 

Or upload then rename on server (if server supports RNFR/RNTO via FTP command), but wput’s built-in rename support may be limited; check server compatibility.


Error handling and troubleshooting

Common issues:

  • Authentication failures: double-check username/password and whether FTPS is required. Use --ask-password to rule out shell-escaped characters causing issues.
  • Connectivity or DNS problems: verify network reachability (ping, telnet host 21) and firewall/port settings.
  • Permission errors on remote server: ensure the FTP user has write privileges in the target directory.
  • Partial uploads: use --continue when the server supports REST/partial transfers.

Increase verbosity (-v) to get more details about failures. Check server-side logs if you control the FTP server.


Alternatives and when not to use Wput

Wput is best when you need a minimal, scriptable FTP uploader. Consider alternatives when:

  • You require SFTP (SSH-based) instead of FTP/FTPS — use scp, sftp (OpenSSH), or rsync over SSH.
  • You need advanced queuing, mirroring, or complex FTP scripting — tools like lftp provide richer features.
  • You want GUI convenience — FileZilla or similar GUI clients are better for manual file management.

Comparison (quick):

Feature Wput lftp sftp/scp
FTP/FTPS upload Yes Yes No
SFTP/SSH No Yes Yes
Advanced mirroring/scripting Basic Powerful Moderate
Lightweight/scripting-friendly Yes No (heavier) Moderate

Security considerations

FTP without TLS transmits credentials and data in plaintext; avoid it on untrusted networks. Prefer FTPS or SFTP for encryption. Limit and rotate credentials used for automation, and run transfers under accounts with the minimum needed privileges.


Summary

Wput is a focused, lightweight command-line uploader for FTP/FTPS that works well in scripts, cron jobs, and minimal environments. Use it when you need straightforward uploads without the complexity of heavier clients. For secure uploads, use FTPS, avoid exposing credentials on the command line, and choose alternatives like SFTP/rsync when appropriate.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *