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 に答える