从 SFTP 文件夹复制并删除文件
2019-06-11
14310
我必须从 SFTP 位置选择(删除)带有文件掩码
FileName_A_*
和
FileName_B_*
的文件,并将它们放在共享驱动器中。
我尝试使用 WinSCP。我已使用以下代码创建了一个
HourlyFile.txt
文件,并将其放在
C:\Program Files (x86)\WinSCP
下。另一个批处理文件
HourlyFile.bat
用于从
HourlyFile.txt
执行脚本
HourlyFile.txt:
option batch abort
option confirm off
open sftp..........
get -filemask="FileName_A_*" /outbound/test/* \\sharedrive
get -filemask="FileName_B_*" /outbound/test/* \\sharedrive
del /outbound/test/FileName_A_*
del /outbound/test/FileName_B_*
exit
HourlyFile.bat:
winscp.com /script=HourlyFile.txt
pause
我尝试使用以下选项删除文件,但收到错误消息
“未知命令”
。此外,上述代码正在从
/outbound/test/
复制子文件夹,但实际上不应该这样做。
尝试的命令:
del /outbound/test/FileName_A_*
-del /outbound/test/FileName_A_*
delete /outbound/test/FileName_A_*
delete /outbound/test/FileName_A_20190604_090002
delete /outbound/test/FileName_A_20190604_090002.csv
3个回答
如果您要下载并删除文件,最好使用
-delete
开关(
get
命令
)。这样,您可以确保 WinSCP 仅删除那些真正成功下载的文件。
get -delete /outbound/test/FileName_A_* \\sharedrive\
get -delete /outbound/test/FileName_B_* \\sharedrive\
请参阅 WinSCP 文章 如何创建同步文件并在之后从源中删除同步文件的脚本?
回答您的字面问题:WinSCP 没有
del
命令。 WinSCP 有
rm
命令
:
rm /outbound/test/FileName_A_*
rm /outbound/test/FileName_B_*
Martin Prikryl
2019-06-11
在某些 Unix 服务器上,通配符命令将是:
mrm /outbound/test/FileName_A_*
,在这种情况下
rm /outbound/test/FileName_A_*
不起作用,返回错误:
rm:访问失败:未找到文件(/outbound/test/FileName_A_*)
access_granted
2021-07-28
WinSCP 的示例脚本:
open ftp://login:password@ip/ -rawsettings Utf=1
lcd "D:\Out " (Your local outgoing directory, from which we upload to the ftp server)
cd /in (The remote directory where we upload it)
put *.txt (upload all txt files)
lcd "D:\In " (local incoming directory or network "\\server\folder" for downloading files from the server)
cd /out (a directory on a remote server from where we download files)
get -delete *.rar (the command takes all rar files and deletes them after successful download)
rm *.zip (just deletes zip files in a remote directory without downloading)
exit
ipdf
2024-04-15