Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 从用户获取文件列表输入以馈送到WinSCP的批处理脚本_Unix_Batch File_Batch Processing_Winscp - Fatal编程技术网

Unix 从用户获取文件列表输入以馈送到WinSCP的批处理脚本

Unix 从用户获取文件列表输入以馈送到WinSCP的批处理脚本,unix,batch-file,batch-processing,winscp,Unix,Batch File,Batch Processing,Winscp,我的要求用于创建ftp批处理脚本,以便通过WinSCP命令行将文件从Unix传输到Windows。因此,我将文件名传递给脚本,文件从Unix传输到Windows。但是,当我想要传输多个文件时,这里的挑战是从用户获取所有文件名,然后运行WinSCP命令来获取所有文件。如何循环输入不同的文件名,并为相同的文件名构造WinSCP命令 由于我是批处理脚本新手,有人能帮我解决这个问题吗 传输单个文件的示例命令 调用C:\Progra~2\WinSCP\WinSCP.exe/console/timeout=

我的要求用于创建ftp批处理脚本,以便通过WinSCP命令行将文件从Unix传输到Windows。因此,我将文件名传递给脚本,文件从Unix传输到Windows。但是,当我想要传输多个文件时,这里的挑战是从用户获取所有文件名,然后运行WinSCP命令来获取所有文件。如何循环输入不同的文件名,并为相同的文件名构造WinSCP命令

由于我是批处理脚本新手,有人能帮我解决这个问题吗

传输单个文件的示例命令

调用C:\Progra~2\WinSCP\WinSCP.exe/console/timeout=“120”/command“option batch continue”“option confirm off”“open sftp://%userid%:%passw%@%host%”“get%/file/filename.txt%”退出

传输多个文件的示例命令

调用C:\Progra~2\WinSCP\WinSCP.exe/console/timeout=“120”/command“选项批处理继续”“选项确认关闭”“打开sftp://%userid%:%passw%@%host%”“get%/file/filename.txt%”“get%/file/filename2.txt%”“get%/file/filename3.txt%”“退出”


我假设您将在控制台中手动提示用户输入。这将反复提示用户输入,直到它看到一个点

@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

在这种情况下,您根本不需要接受多个输入。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时,使用可避免打开WinSCP的其他控制台窗口
  • 命令行参数
    /timeout=120
    不适用于使用脚本中的
    open
    命令打开的会话。使用以下按钮的
    -timeout=120
    开关:

  • 使用
    call
    命令运行WinSCP毫无意义


您打算手动获取用户输入吗?谢谢。这对我有用。但我面临一个问题。在运行时,winscp命令不接受合并输入值。它以--call C:\Progra~2\WinSCP\WinSCP.exe/console/timeout=“120”/command“option batch continue”“option confirm off”“open sftp://%userid%:%passw%@%host%”的形式运行,可能是因为WinSCP需要以
get%/file/filename.txt%
的形式输入。上面的脚本没有在输入中添加单词
get
。如果您想像示例中所说的那样添加
get
,请替换行
get input\u all=!输入旧的!“!input!”
获取输入\u all=!”!输入旧的!“获取!输入!”
然后再试。我已经只使用了该选项。在开始标签中:set/p consolidated\u input=!全部输入@echo ON echo%consolidated\u input%cd C:\Users\ebavkar\Documents\Projects\VMware\Scripts call C:\Progra~2\WinSCP\WinSCP.exe/console/timeout=“120”/command“option batch continue”“option confirm off”“open sftp://%userin%:%pasw%@%host%”“%consolidated\u input%”您的示例没有显示如何添加
get
部分。假设你有这个权利。。。您还需要删除
%consolidated\u input%
周围的双QOUTE。您需要确保在循环中的每个
get filename
对周围添加双引号。因此,生成的语法与问题中的语法相同,即
“get/xxx/filename1”“get/xxx/filename2”
open sftp://%userid%:%passw%@%host% -timeout=120