Can wget Recursively Download from FTP?
Yes, the wget command-line utility is fully
capable of recursively downloading files and directories from an FTP
server. This article provides a quick overview of how
wget handles recursive FTP transfers, outlines the
essential command-line flags required for the task, and highlights key
security and performance configurations to optimize your downloads.
Understanding Recursive FTP Downloads with wget
By default, wget only downloads a single specified file.
However, when dealing with FTP servers that contain complex nested
directories, you can trigger a recursive download. In this mode,
wget acts like a web crawler for the FTP file structure: it
enters the initial directory, parses the file listings, downloads all
available items, and then moves deeper into the subdirectories to repeat
the process.
To initiate a basic recursive download from an FTP server, you use
the -r (or --recursive) flag. A standard
command looks like this:
wget -r ftp://username:password@ftp.example.com/directory/
Essential Flags for FTP Recursion
To gain finer control over what gets downloaded and how the local file structure is built, you can combine the recursive flag with several other options:
-l <depth>(or--level=<depth>): Controls how many levels deepwgetwill traverse into the subdirectories. The default maximum depth is 5. If you want to download everything regardless of depth, use-l 0or--level=inf.--no-parent(or-np): Crucial for FTP downloads. This preventswgetfrom escaping the initial directory you specified and wandering upward into parent directories on the server.-m(or--mirror): A shortcut flag that turns on recursion, sets the infinite depth limit, keeps session links alive, and preserves the server’s file timestamps locally. It is the ideal choice for backing up an entire FTP directory.
Handling Authentication and Connection Issues
FTP servers often require user credentials. You can pass these directly in the URL string or use dedicated flags to keep your command history cleaner:
wget --ftp-user="your_username" --ftp-password="your_password" -r ftp://ftp.example.com/target-folder/
If you are downloading a massive archive, network interruptions can
break the process. Adding the -c (or
--continue) flag ensures that if the connection drops,
wget will resume downloading partially completed files from
where it left off, rather than starting over from scratch.