乐闻世界logo
搜索文章和话题

How to recursively download a folder via FTP on Linux

1个答案

1

Commonly, you can use command-line tools like wget or FTP clients such as lftp to accomplish this task. Below are examples using both methods:

Using wget:

Usage is straightforward; you can achieve this with the following command:

bash
wget -r --ftp-user=username --ftp-password=password ftp://server_address/path/

Here's a breakdown of the parameters:

  • -r: Recursively download files
  • --ftp-user: FTP username
  • --ftp-password: FTP password
  • ftp://server_address/path/: The path to the folder on the FTP server you want to recursively download

For example, if you want to download files from the /files directory on ftp.example.com, with username user and password pass, you can run:

bash
wget -r --ftp-user=user --ftp-password=pass ftp://ftp.example.com/files/

Using lftp:

lftp is another powerful command-line tool designed specifically for file transfers. It supports FTP, FTPS, HTTP, HTTPS, HFTP, FISH, SFTP, and more protocols. The command to recursively download a folder using lftp is as follows:

bash
lftp -u username,password server_address -e "mirror /remote_folder_path /local_destination_path; quit"

Here's a breakdown of the parameters:

  • -u username,password: FTP username and password
  • server_address: The address of the FTP server
  • mirror /remote_folder_path /local_destination_path: The mirror command copies the remote directory to the local directory
  • quit: Exit lftp after completion

For example, if you want to download files from the /files directory on ftp.example.com to the local /local/dir directory, with username user and password pass, you can run:

bash
lftp -u user,pass ftp.example.com -e "mirror /files /local/dir; quit"

In any case, if you're performing this operation within a corporate network, you may need to comply with relevant data protection policies and security protocols. Additionally, some folders may have permission restrictions, and you may need specific permissions to download files from them. If you encounter issues while using these commands, you should check your network connection, FTP server status, whether your username and password are correct, and whether you have appropriate file access permissions.

2024年6月29日 12:07 回复

你的答案