Topic "Checking result of the script and moving local files"

Author Message
Tony_
[View user's profile]

Joined: 2015-06-24
Posts: 2
Location: NYC
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: http://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: http://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:

Code:
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.
Advertisements
Tony_
[View user's profile]

Joined: 2015-06-24
Posts: 2
Location: NYC
Just bumping this topic to see if anyone has an answer.

TIA,
-Tony.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Code:
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).
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.
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.
Fairfielder
[View user's profile]

Joined: 2015-12-31
Posts: 2
prikryl wrote:
Code:
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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
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:
http://stackoverflow.com/q/34558304/850848

We need to see your script to help you.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License