0

如何使用批处理脚本在 ftp 中下载多个文件。我在记事本中有一个包含确切目录的文件列表,我想迭代它们以下载每个文件。此外,应在下载时创建文件夹和子文件夹。

请帮忙。

4

1 回答 1

2

Use the scripting function of FTP.exe.

Put the following batch file in your downloads directory, along with the list of files to be downloaded. Change UserName to the username you will use, PassWord to the password you will use, ftp.site.com to the name of the ftp site you'll be downloading from, and filelist.txt with the name and path of the file that the list of files to be downloaded is being kept in.

makescript.bat

:: Set needed Variables
set ftpUserName=UserName
set ftpPassword=PassWord
set ftpSite=ftp.site.com
set filelist=filelist.txt
set script=script.txt

if exist script.txt del script.txt

:: Create Script
echo connect %ftpSite%>> %script%
echo %ftpUserName%>> %script%
echo %ftpPassWord%>> %script%

for /f "tokens=0" %%x in (%filelist%) do (
  echo cd %%~px>> %script%
  if "%%~xx"=="txt" (
    echo ascii>> %script%
  ) else (
    echo binary>> %script%
  )
  echo get %%~nxx>> %script%
)

echo quit>> %script%

The above assumes that there are no spaces in the paths or filenames, and that the file with the names and paths of the files to be downloaded is in this form:

\path\to\file\file.exe

Run makescript.bat, then type, or add the following line to a batch file:

ftp -s:script.txt

FTP will log on to the ftp site, send the username and password, change directories, then download a file, change directories, then download another file. This will repeat until all the files have been downloaded.

于 2012-10-22T16:55:51.107 回答