调用WinSCP以检查主机上的文件是否存在或不使用批处理文件-每天运行 [英] Call WinSCP to check if files on a host exist or not using a batch file - to run everyday
问题描述
我正在尝试使用WinSCP自动执行对远程服务器的呼叫,这是一项多余的日常任务.我希望该批处理文件调用远程计算机-提供用户名和密码,然后检查文件是否存在.
到目前为止,我已经能够启动WinSCP服务器,但批处理文件仍不占用用户名和密码-它仍在询问用户名和/或提供有关过多参数的错误.
chdir /d D:\Program Files\WinSCP\
winscp.com 172.18.186.39 username password
您的语法甚至与远程用于编写脚本的WinSCP命令行语法.
@echo off
set REMOTE_PATH=/home/user/test.txt
winscp.com /command ^
"open ftp://username:password@ftp.example.com/" ^
"stat %REMOTE_PATH%" ^
"exit"
if %ERRORLEVEL% neq 0 goto error
echo File %REMOTE_PATH% exists
rem Do something
exit /b 0
:error
echo Error or file %REMOTE_PATH% not exists
exit /b 1
上面的示例是针对FTP协议的.您没有告诉使用您正在使用什么协议.如果不是FTP,则必须相应地更改 open
命令.
您可以 WinSCP GUI为您生成open
命令./p>
准备好批处理文件后,请使用 Windows Scheduler定期调用它./p>
I am trying to automate a call to a remote server using WinSCP which is a redundant everyday task. I want the batch file to call remote machine - provide username and password, and later check for if files exist.
So far I am able to start a WinSCP server but still the batch file does not consume username and password - it is still asking for them and/or providing an error regarding too many arguments.
chdir /d D:\Program Files\WinSCP\
winscp.com 172.18.186.39 username password
Your syntax does not even remotely resemble WinSCP command-line syntax for scripting.
See WinSCP article on Checking file existence using scripting:
@echo off
set REMOTE_PATH=/home/user/test.txt
winscp.com /command ^
"open ftp://username:password@ftp.example.com/" ^
"stat %REMOTE_PATH%" ^
"exit"
if %ERRORLEVEL% neq 0 goto error
echo File %REMOTE_PATH% exists
rem Do something
exit /b 0
:error
echo Error or file %REMOTE_PATH% not exists
exit /b 1
The above example is for FTP protocol. You didn't tell use what protocol are you using. If not FTP, you have to change the open
command accordingly.
You can have WinSCP GUI generate the open
command for you.
Once you have the batch file ready, use Windows Scheduler to call it regularly.
这篇关于调用WinSCP以检查主机上的文件是否存在或不使用批处理文件-每天运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!