我有一个脚本应该列出 SFTP 服务器中的所有文件并将其输出到一个文件中(供另一个脚本使用)。产生所需输出的 cmd 是:
echo ls | psftp -l myusername -pw mycomplexpwd FTPServerHostname > C:/Users/myuser/Desktop/ls.txt
这将由 Windows 任务计划程序每天调用几次。出于某种原因,在调度此命令(在 .bat 文件中)并通过 user 运行时SYSTEM
,输出文件将仅包含以下内容:
Remote working directory is /
psftp> quit
当使用另一个用户时,输出是预期的(所有文件的列表) -请参阅https://serverfault.com/questions/1084015/why-psftp-script-is-failing-when-ran-as-system。我需要一种编写脚本的方法,并且能够SYSTEM
像我在该系统中的其他脚本一样运行它。我也尝试过以下方法:
psftp -l myusername -pw mycomplexpwd FTPServerHostname < C:/Users/myuser/Desktop/lscmd.txt > C:/Users/myuser/Desktop/ls.txt
和:
psftp -l myusername -pw mycomplexpwd FTPServerHostname -b C:/Users/myuser/Desktop/lscmd.txt > C:/Users/myuser/Desktop/ls.txt
其中 lscmd.txt 包含以下内容:
ls
并且行为是相同的。编辑:正如下面的 Martin 所指出的,下面可能没有生成相同的输出,而是没有触及文件。然而并没有产生预期的结果。
我能做些什么来做需要的行为?
操作系统是 Windows Server 2012 R2。