Commands.page Logo

Wget Option to Preserve File Permissions on Ubuntu

This article provides a concise overview of the specific wget command-line flag required to maintain remote file permissions during downloads on Ubuntu. It details the correct syntax, provides a usage example, and clarifies the protocol limitations regarding HTTP and FTP transfers.

The option that allows wget to download a file and preserve file permissions is --preserve-permissions. By default, wget may apply local umask settings to downloaded files, but this flag instructs the utility to retain the original permission bits from the remote server.

To implement this, add the flag to your command string. The basic syntax is:

wget --preserve-permissions [URL]

For example, to download a script from an FTP server while keeping it executable:

wget --preserve-permissions ftp://example.com/script.sh

It is critical to understand that this option functions primarily with FTP protocols. When downloading via HTTP or HTTPS, the server does not transmit Unix permission metadata. Consequently, wget creates HTTP downloads using default local permissions regardless of this flag. For HTTP files, you must manually adjust permissions using the chmod command after the download finishes.