使用 WinSCP 从 SFTP 服务器下载文本文件时跳过重复行

Skip duplicate lines when downloading text file from SFTP server with WinSCP

是否有 WinSCP 批处理文件只将远程文件中的非重复值附加到本地文件的命令?

这是我的批处理命令:

@echo off

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\Users\U37615\Documents\POCLOSEBATCHLOG\WinSCP.log" /ini=nul ^
  /command ^
    "open xxxxxx -hostkey=""ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx....""" ^
    "get -append -delete xxxxxx"" ""xxxxxxx""" ^
    "exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)

pause
exit /b %WINSCP_RESULT%

我在远程服务器上有一个文本文件,我想将其附加到本地文件,但我只想附加本地列表中不存在的项目。对命令有任何想法或解决此问题吗?

绝对不是。这是一个自定义要求,您不能合理地期望任何 SFTP 客户端开箱即用地支持它。


将远程文件(没有-append)下载到本地临时文件(temp.txt)。

然后做类似的事情:

powershell -Command "type local.txt, temp.txt | sort -unique > combined.txt"

一些参考资料:

  • Using windows/dos shell/batch commands, how do I take a file and only keep unique lines?
  • How do I concatenate two text files in PowerShell?