繁体   English   中英

如何使用具有文件名列表作为输入的txt文件从FTP服务器下载这些文件?

[英]How to use a txt file that has a list of filenames as input, to download those files from FTP server?

我有一个基本的批处理文件,该文件连接到FTP服务器,并将所有csv文件中的列表另存为便携式计算机上的txt文件。
稍后,我将要下载该列表上的所有文件(使用txt文件的每一行作为批处理文件的输入),还将FTP服务器上的每个文件“移动”到FTP服务器上的另一个文件夹。

List.txt包含:

 A.csv
 B.csv
 C.csv
 etc...

批处理文件使用List.txt作为输入:

  1. 连接到FTP服务器
  2. 然后对于List.txt的每一行
  3. 获取文件名
  4. REN文件名/其他文件夹/文件名
  5. 关闭连接

我可以连接到FTP服务器,但是当我尝试在批处理中使用for /f %%i ,它将在FTP Shell之外执行。

Open example.com
user
password
binary
for /f %%i in "List.txt" do get %%i
disconnect
bye
@echo off
rem making the ftp script
(
  echo Open example.com
  echo user
  echo password
  echo binary
)>ftp.txt
for /f "delims=" %%i in (List.txt) do echo get %%i>>ftp.txt
(
  echo disconnect
  echo bye
)>>ftp.txt

rem connecting to ftp
ftp -s:ftp.txt

编辑:
您必须阅读的资源https://technet.microsoft.com/zh-cn/library/cc959810.aspx

样品:

!     Runs the specified command on the local computer.  
?     Displays descriptions for Ftp commands. ? is identical to help .  
Mget  Copies multiple remote files to the local host using the current file transfer type.

感谢保罗的回答,我意识到了我的问题。 这是我所做的:

@echo off
REM Enter the username
echo user USERNAME> ftpcmd.dat

REM Enter the password
echo PASSWORD>> ftpcmd.dat

REM Change the local computers' directory
echo lcd D:\LocalFolder\>> ftpcmd.dat

REM create the list of commands to download the csv files, and then
REM 'move' them to the Backup folder
for /f "usebackq delims=" %%i in ("d:\LocalFolder\List.txt") do (echo get %%i>>ftpcmd.dat) && (echo ren %%i /Backup/%%i>>ftpcmd.dat)

REM Close the connection
echo quit >> ftpcmd.dat

REM use -d for debugging, -i for preventing user interaction questions
ftp  -i -n -s:ftpcmd.dat ftp.example.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM