Re: How to check file existence on local and remote path, then stop script if it does not exist
Problem description Upload Script:
At the start the script should check if files are present on the localpath, if yes the script should be executed to the end and if no the script should be aborted.
Checking for an existence of local files in not a WinSCP question.
Anyway, you can use
Test-Path
:
https://winscp.net/eng/docs/script_checking_file_existence#local
Problem description Download Script:
After the script has successfully established the session via SFTP to the server, the script should first check if files are available on this server or not, if the files are not available the script should be terminated and if files are available the script should be executed until the end.
That's exactly what your script does now. It does not need any change.
Anyway, again, see:
https://winscp.net/eng/docs/script_checking_file_existence#library
Though note that you should not use
Session.GetFiles
followed by Session.RemoveFiles
. That's not transactionally safe. You might end up deleting files that were not downloaded. Instead use remove
argument of Session.GetFiles
. The same way you do with Session.PutFiles
in your upload script.
$session.GetFiles("/%REMOTEPATH%/*", "%LOCALPATH%\*", $True).Check()