使用WinSCP脚本复制具有名称条件的文件

时间:2019-06-26 06:34:56

标签: batch-file sftp winscp

我有一个Test文件夹,其中包含具有两种文件名的多个文件,如下所示:

Cycle2605.zip
Cycle2605_P.zip
Cycle2705.zip
Cycle2705_P.zip

我要做的是,通过WinSCP SFTP将所有文件从文件夹移动到其他服务器,如下面的代码所示。

open sftp://user:password@hostname/ -hostkey="ecdsa-sha2*******"
put D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in
exit

但是如何将文件名中不包含_P的文件移到目标而不是移到所有文件?

open sftp://user:password@hostname/ -hostkey="ecdsa-sha2*******"
if <filename not contain _p> echo put D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in
exit

1 个答案:

答案 0 :(得分:2)

您可以使用matching certain pattern排除文件-filemask switch

shubuntu1@shubuntu1:~/99$ docker exec -it mychrome wget -q -O - http://foo.bar
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

或者,如果文件名约定允许,则只能选择所需的文件,例如:

put -filemask=|*_P.zip D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in

在这种情况下,直接在source path中使用Windows通配符会更容易:

put -filemask=Cycle????.zip D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in