Checking result of the script and moving local files

Advertisement

Tony_
Joined:
Posts:
1
Location:
NYC

Checking result of the script and moving local files

Hello,

I need to do the following:

1. Move all the files that fall under certain pattern (in this case all csv files that start with GL_.... GL_*.csv) from local machine to a remote SFTP server;
2. Check if the move was successful;
3. If it was, move all the local files to another directory

I got the 1st part working somewhat. I created a batch file and am able to run it from the command line. It moves the files from the local machine to the remote SFTP server just fine (I still need to figure out how to automate this process...probably via Windows scheduler).
I'm not sure how to check for the successful script execution and based on that build a logic to move the local files to another directory.

I saw an example here: https://winscp.net/eng/docs/guide_automation#results but I cannot figure out where all of that stuff belongs to. I need to make it part of the same batch file I'm executing from the command line.

Furthermore, it sounds like I cannot really move local files to another location using batch scripting? I found an example here: https://winscp.net/eng/docs/script_local_move_after_successful_upload but again, I'm not sure where to add this stuff after executing batch file:
if %ERRORLEVEL% neq 0 goto error
 
echo Upload succeeded, moving local files
move *.* c:\backup\
exit 0
 
:error
echo Upload failed, keeping local files
exit 1

TIA,
-Tony.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Checking result of the script and moving local files

winscp.com /script=example.txt
if %ERRORLEVEL% neq 0 goto error
 
echo Upload succeeded, moving local files
move *.* c:\backup\
exit 0
 
:error
echo Upload failed, keeping local files
exit 1
The above code is a Windows batch file (.bat), that first runs WinSCP to upload the files and than moves the uploaded files away (using Windows shell commands).

Reply with quote

Tony__
Guest

I think I figured it out. I missed the point that the scrip should be in a separate file and MOVE in a bat file.
Now I just need to figure out how to append messages (either successful or unsuccessful) to a log file.
Appreciate your help,
-Tony.

Reply with quote

Advertisement

You can post new topics in this forum