wput is a dedicated command-line FTP client designed specifically to upload files and directories to a remote server. Mimicking the behavior of wget (which is built for downloading), wput is non-interactive, background-capable, and features built-in resume features. This makes it an ideal tool for shell scripts and automated cron jobs. Standard Directory Copying Syntax
To recursively upload an entire local directory to an FTP server, use the following syntax structure:
wput /path/to/local/directory/ ftp://username:password@://remote-server.com Use code with caution. Critical Configuration Pitfalls
When copying entire directories using wput, pay close attention to two exact behaviors that can disrupt your target folder structure:
Directory Tree Recreation: By default, wput may copy the entire absolute folder sequence from your local drive onto the remote server. For example, uploading /var/www/site/ might mistakenly produce /destination/path/var/www/site/ on the server.
The Basename Fix: To cleanly upload only the inner folder contents (or target directory itself), deploy the –basename flag. This tells wput which part of the local path to cut off during the transfer.
wput –basename=/var/www/ /var/www/site/ ftp://user:pass@://server.com Use code with caution. Essential Tutorial Flags
The power of wput lies in its arguments. You can optimize directory copying using these functional options:
–basename=path: Truncates the specified prefix path from input files before creating the target remote path.
-nc / –dont-continue: Stops wput from resuming files. It will instead skip or overwrite matching existing remote files depending on system flags.
-u / –reupload: Forces the tool to completely overwrite existing files on the destination server, ignoring timestamps or size checks.
-N / –timestamping: Only uploads local files if they are newer than the files already present on the remote host.
-b / –background: Immediately pushes the process to the background, writing output to a log file so you can close your active terminal workspace. Security Warning
Because wput requires you to pass your credentials directly through a plaintext URL string (e.g., ftp://user:pass@host), your remote server password will remain visible in your shell’s command history file. For a cleaner, automated production environment, you can look up alternative command-line automation tools like lftp or rsync over SSH.
Are you looking to build an automated backup script, or do you need help hiding your FTP password credentials from the terminal history log? How to Securely Transfer Files Between Servers with scp
Leave a Reply