You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何基于FTP服务器压缩包内的路径列表批量下载图片?

Great question! Batch downloading those images from FTP based on your TXT file is totally doable with a few simple scripting steps. Here are three reliable methods you can use, depending on your operating system and tools available:

Method 1: Standard FTP Client with Batch Script (Cross-Platform)

This uses the built-in FTP client that comes with most operating systems:

  1. First, extract the TXT file from your compressed package. Let’s assume the extracted file is named image_paths.txt.
  2. Generate a list of FTP get commands from the TXT file. Each line has the local filename first, then the remote path—we only need those two fields:
    • On Linux/macOS, run this in the terminal:
      awk '{print "get " $2 " " $1}' image_paths.txt > ftp_commands.txt
      
    • On Windows (PowerShell):
      Get-Content image_paths.txt | ForEach-Object { $parts = $_.Split(); "get $($parts[1]) $($parts[0])" } | Out-File -Encoding ASCII ftp_commands.txt
      
  3. Edit the ftp_commands.txt file to add server connection details at the top, and a quit command at the end:
    open your-ftp-server.com
    your-ftp-username
    your-ftp-password
    # (all the generated get commands will be here)
    quit
    
  4. Run the script:
    • Linux/macOS: ftp -n < ftp_commands.txt
    • Windows: ftp -s:ftp_commands.txt

Note: Storing passwords in plain text is insecure. For safer access, use a .netrc file (Linux/macOS) or configure saved FTP credentials (Windows).

Method 2: Using lftp (Linux/macOS/WSL)

lftp is a powerful, script-friendly FTP client that handles batch operations smoothly. Install it first with sudo apt install lftp (Debian/Ubuntu) or brew install lftp (macOS):

  1. Extract your image_paths.txt file.
  2. Run this command (replace placeholders with your FTP details):
    lftp -u your-username,your-password your-ftp-server.com -e "$(awk '{print "get " $2 " " $1}' image_paths.txt); quit"
    

You can omit the password from the command to be prompted for it, or store credentials securely in ~/.lftprc.

Method 3: Using curl (Cross-Platform)

curl works with FTP and is widely available across systems:

  1. Extract image_paths.txt.
  2. Run this loop to download each file:
    • Linux/macOS:
      while read -r local_file remote_path hash; do
        curl ftp://your-username:your-password@your-ftp-server.com$remote_path -o "$local_file"
      done < image_paths.txt
      
    • Windows PowerShell:
      $ftpPrefix = "ftp://your-username:your-password@your-ftp-server.com"
      Get-Content image_paths.txt | ForEach-Object {
          $parts = $_.Split()
          curl "$ftpPrefix$($parts[1])" -o $parts[0]
      }
      

For better security, use curl --netrc to pull credentials from a .netrc file instead of hardcoding them.

内容的提问来源于stack exchange,提问作者Xullien

火山引擎 最新活动