我的要求是创建一个ftp批处理脚本,通过WinSCP命令行将文件从Unix传输到Windows。因此,我将文件名传递给脚本,文件从Unix传输到Windows。但是,当我想要传输多个文件时,这里的挑战是从用户获取所有文件名并运行WinSCP命令来获取所有文件。如何循环不同文件名的输入并构造相同的WinSCP命令?
有人能帮助我的方法,因为我是新的批处理脚本吗?
示例命令以传输单个文件
调用C:\Progra~2\WinSCP\WinSCP.exe /console /timeout="120“/command选项批处理继续”选项确认关闭“”打开s/timeout= "get %/file/filename.txt%“退出”
传递多个文件的示例命令()
调用C:\Progra~2\WinSCP\WinSCP.exe /console /timeout="120“/command选项批处理继续”选项确认关闭“"open s/timeout= "get %/file/filename.txt%”get %/file/filename2.txt%“"get %/file/filename3.txt%”"exit“
发布于 2014-08-24 07:59:23
在这种情况下,您根本不必接受多个输入。WinSCP命令get可以将多个源文件作为参数。您只需使用目标路径作为最后一个参数。使用.\下载到当前工作目录(仅使用单个参数时是默认的,就像在示例中一样)。
因此,您只能提示用户一次输入要下载的以空格分隔的文件列表。
set /p "list=Enter space separated list of files to download: "
winscp.com /command ^
"option batch continue" ^
"option confirm off" ^
"open sftp://%userid%:%passw%@%host%" ^
"get %list% .\" ^
"exit"边注:
winscp.exe来避免为WinSCP打开额外的控制台窗口。/timeout=120不适用于使用脚本中的open命令打开的会话。使用-timeout=120开关的 command:
打开s ftp://%userid%:%passw%@%host% -timeout=120call命令运行WinSCP没有意义发布于 2014-08-24 07:17:25
我假设您将在控制台中手动提示用户输入。这将提示用户重复输入,直到它看到一个点.。
@echo off
setlocal enabledelayedexpansion
:prompt
set /p "input=Enter the filename:"
if "!input!"=="." (
goto :begin ) else (
set input_all=!input_old! "!input!"
set input_old=!input_all!
goto :prompt
)
:begin
echo consolidated_input=!input_all! 在标签之后添加winscp命令行:开始
测试样本-
D:\Scripts>draft.bat
Enter the filename:c:\sample\test1.txt
Enter the filename:c:\sample\test2.log
Enter the filename:c:\sample\test3.ini
Enter the filename:.
consolidated_input= "c:\sample\test1.txt" "c:\sample\test2.log" "c:\sample\test3.ini"干杯,G
https://stackoverflow.com/questions/25469071
复制相似问题