windows winscp中执行批处理文件的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5382964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:28:17  来源:igfitidea点击:

Problem in executing the batch file in winscp

windowsbatch-filewinscp

提问by Shahsra

I am new to Winscp and I am having a problem in executing a batch file.

我是 Winscp 的新手,在执行批处理文件时遇到问题。

The scenario is something like this:

场景是这样的:

I have a batch file A, two folders (up B and down folders C), some text files in up folder D, a text file E (different from the files in D) and a ppk file F. All these things are in one folder only.

我有一个批处理文件 A、两个文件夹(上 B 和下文件夹 C)、上文件夹 D 中的一些文本文件、一个文本文件 E(与 D 中的文件不同)和一个 ppk 文件 F。所有这些都合二为一仅文件夹。

The batch file A is having a script (script is shown below) which contains text. If that text contents are true (means if that text (text contents are related to E i.e. if the text file E is executed) is executed) then only the files in up folder B moves to down folder C.

批处理文件 A 有一个包含文本的脚本(脚本如下所示)。如果该文本内容为真(意味着如果该文本(文本内容与 E 相关,即如果文本文件 E 被执行)被执行),则只有上文件夹 B 中的文件移动到下文件夹 C。

And the script in batch file A is:

批处理文件A中的脚本是:

C:\somefolder\WinSCP3.exe /console /script=E.txt /log=session.log
if errorlevel 1 goto error
xcopy C:\somefolder\up\*.*  C:\somefolder\down\  /y
del  C:\somefolder\up\*.*   /Q
:error
echo Upload failed, keeping local files

And the content in text file E is:

而文本文件E中的内容是:

option batch abort
option confirm off
open @test.com 
change remote directory
cd \somedirectory
option transfer binary
put C:\somefolder\up\*.*
close
exit

I don't know why the files from up folder is not moving to down folder.

我不知道为什么 up 文件夹中的文件没有移动到 down 文件夹。

Please let me know where exactly the problem is and how to resolve that problem....

请让我知道问题究竟出在哪里以及如何解决该问题......

回答by Shahsra

Thanks to Andriy M. His comments cleared my confusion and gave the right answer.

感谢 Andriy M。他的评论消除了我的困惑并给出了正确的答案。

Here are the right syntax.

这是正确的语法。

C:\somefolder\WinSCP3.exe /console /script=E.txt /log=session.log

xcopy C:\somefolder\up\*.*  C:\somefolder\down\  /y
del  C:\somefolder\up\*.*   /Q

if errorlevel 1 goto error

:error
echo Upload failed, keeping local files

The content in text file E.txt is:

文本文件 E.txt 中的内容为:

option batch abort
option confirm off
open @test.com 
change remote directory
cd \somedirectory
option transfer binary
put C:\somefolder\up\*.*
close
exit

回答by Shen

Dunno if anyone still read this thread or not.. But what I know is "put" command upload the files from Local Directory to Remote Directory. TS wanted to "download the files from Remote Directory to Local Directory" so I think the right command is "get".

不知道是否有人仍然阅读此线程。但我所知道的是“放置”命令将文件从本地目录上传到远程目录。TS 想要“将文件从远程目录下载到本地目录”,所以我认为正确的命令是“get”。

Cheers, Shen

干杯,沉