Call WinSCP to check if files on a host exist or not using a batch file - to run everyday

邮差的信 提交于 2019-12-19 11:15:14

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/45136462/call-winscp-to-check-if-files-on-a-host-exist-or-not-using-a-batch-file-to-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!