Checking result of the script and moving local files

Advertisement

Tony_
Joined:
Posts:
2
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 SFT 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:
27,226
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

Hi,

Thanks for your help.

When I run my batch file, it actually gets the local file and uploads it to the remote server but when I try to use MOVE command to move the local file to another local directory, I get an error message "Unknown command 'move'"
Any ideas how I can accomplish what I need?

TIA,
-Tony.

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

Fairfielder
Joined:
Posts:
2

Re: Checking result of the script and moving local files

martin wrote:

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).

When I run the above as a .bat file on my Windows 7 computer, it does the file transfer, but ignores what comes after.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

Re: Checking result of the script and moving local files

Fairfielder wrote:

When I run the above as a .bat file on my Windows 7 computer, it does the file transfer, but ignores what comes after.
Your duplicate question on StackOverflow:
https://stackoverflow.com/q/34558304/850848

We need to see your script to help you.

Reply with quote

Advertisement

You can post new topics in this forum