Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Guest

Re: %WINSCP_RESULT%

Thanks Martin,

Wow! Not sure how I missed that.

Please accept my apologies for pointing the finger at WINSCP.

Makes perfect sense now. The log file I emailed of task failure was only written to on the first time through the script. So if a failure occurred on the second run, it still sent the first log file containing the success log. The reason I was getting off track is that the host we connected to only supports one connection so ultimately one of the other log files show the connection error making it look like WINSCP was getting the error result from the other job.

Many, many thanks for your help!
martin

Re: %WINSCP_RESULT%

The problem is that the script actually runs twice.

First, the primary script instance call a secondary instance (with redirection). Once the secondary instance finishes, the call returns and the primary instance continues with the same task. Just try to run the batch file manually. You will see WinSCP output, despite a seeming redirection. Because only the secondary instance is redirected. The primary instance is not.

If the primary (non-redirected) instance fails, it will send successful log of the previous (redirected) secondary instance.

You should add exit after the call.
Guest

Re: %WINSCP_RESULT%

Hi Martin,

I hear what you saying and yes it is a batch related issue. I just understand how the script gets a result of 0 and still sends the email.

I use the call feature because it creates the perfect log file of what would be seen on the screen if you run the winscp task manually

I have attached an image of the script and also the Email generated. Note: that the email shows "Success" and also the value of WINSCP_RESULT [0]. So in theory the email should not have been sent.
martin

Re: %WINSCP_RESULT%

If you need our help, please post a minimal and full example that reproduces the problem.

You keep posting partial and redacted scripts. What you describe does not make sense, and I'm pretty sure, it's not, what is really happening. We cannot help you, if you do not show us the exact code.

Also, why do you use call at all? What do you need it for?

And anyway, note that you have problems with batch file scripting. This is not really a WinSCP question.
Guest

Re: %WINSCP_RESULT%

Within my batch file I call :transfer and then redirect the "transfer output" to a log file

call :transfer > c:\transfer\transfer.log:

I understand that the call command can mess with the environmental variables. Is there a better way to get just the "transfer details" i.e what you would see when you run winscp.
The full winscp logs are too detailed.

G.
Guest

Re: %WINSCP_RESULT%

Just out of interest, I assume this is a batch script related issue. If I used .net or C are there error options any better?

Has anyone one got a working script example to share?


G.
Guest

Re: %WINSCP_RESULT%

It seems I spoke to soon.

I received an Email this morning that contained the success log file for a transfer. At exactly the same time, there was another transfer that failed. One of the transfers was using set %WINSCP_RESULT1%=!errorlevel! and the other set %winscp_result%=%errorlevel%. One of the jobs was configured to send a log file the other wasn't.

The log file [log.log] attached to the Email contains the word Success. If it was a success how did I get the log file? If it was a failure, why does the log contain the word Success?

set WINSCP_RESULT1=!ERRORLEVEL!
if %WINSCP_RESULT1% equ 0 (
echo Success
) else (
echo Error
c:\Blat\Blat.exe "C:\log.log" -Subject "Issues with the transfer" -to myemail@site.com -f transfer@site.com -server mailserverip >nul
)

I'm really confused!
martin

Re: %WINSCP_RESULT%

Anonymous wrote:

So this makes me think that when we set WINSCP_RESULT=%ERRORLEVEL%, I am getting the %ERRORLEVEL% from the other failed transfer. The Failed transfer status generates an Email, unfortunately just not for the right job.

I don't think the %WINSCP_RESULT% variable is being shared between batch scripts [I don't think we can do that easily]. I think the issue is that when we check the %errorlevel% and set the %winscp_result% variable we are using the results from the wrong job.

This does not make any sense. But I'm glad you have resolved your problem.
Guest

Re: %WINSCP_RESULT%

I seem to have solved this weird issue in the following way

I have added this to each script
setlocal EnableDelayedExpansion [Recommended by a lot of people https://ss64.com/nt/delayedexpansion.html ]
I have changed the line set WINSCP_RESULT=%ERRORLEVEL% to set WINSCP_RESULT3=!ERRORLEVEL!
[I have giving each WINSCP_RESULT a number so that each batch file is unique, they shouldn't share this variable but just in case.]

I now get the right log file when the transfer errors.
Guest

Re: %WINSCP_RESULT%

So this makes me think that when we set WINSCP_RESULT=%ERRORLEVEL%, I am getting the %ERRORLEVEL% from the other failed transfer. The Failed transfer status generates an Email, unfortunately just not for the right job.

I don't think the %WINSCP_RESULT% variable is being shared between batch scripts [I don't think we can do that easily]. I think the issue is that when we check the %errorlevel% and set the %winscp_result% variable we are using the results from the wrong job.



G.
Guest

Re: %WINSCP_RESULT%

Hi Martin.

Apologies for the confusion. I edited my configs and log file names to hide the companies involved. Unfortunately, I have confused you.

Trust me when I say the log file names for winscp are unique. They roll every 24 hours.
The log files sent by the email have affixed name that matches the batch script that runs. These files are overwritten each time the script runs.

Unfortunately, the company we are sending files to only allow one active user and there are 8 or 9 transfers competing for the one logon. It isn't ideal and none of this is your problem.

I changed the email setup so it doesn't send any log files but instead just sends an email with a subject line containing the name of the transfer running.
So this afternoon I got a failure email. The subject told me which log files to look at. When I looked at the log file it showed the transfer as a success. When I looked at the other log files I did however find another transfer that failed at exactly the same time.
martin

Re: %WINSCP_RESULT%

Anonymous wrote:

The log files have unique names and there is no way that the wrong log file is being sent.

What makes them unique?
All I can see that you add a date to the file name. But that won't make them unique:
set datestamp=%date:~10,4%%date:~7,2%%date:~4,2%

And actually you email a different file than you log to:
c:\Blat\Blat.exe C:\\logs\Outstanding.log -to my@email.com -f FTP_donotreply@email.com -server x.x.x.x >nul

So that can be the problem!
Guest

Re: %WINSCP_RESULT%

Does anyone have any ideas?
Guest

Re: %WINSCP_RESULT%

The log files have unique names and there is no way that the wrong log file is being sent.

If you setup two tasks to the same site. If in the first task you deliberately generate an error and in the second task you just connect and disconnect and then check the WINSCP_Result you can see that the WINSCP result of the failed job appears in the successful job when checked.
martin

Re: %WINSCP_RESULT%

Is this happening because I have multiple transfers happening on the same site?

If they log to the same folder, the logs will overwrite one another. Make sure the log name is unique for each parallel transfer/batch file.
Guest

Re: %WINSCP_RESULT%

ok the plot thickens a little

We received the following error email [edited]

Subject Prod-Outbound-Outstanding.log
Searching for host...
Connecting to host...
Authenticating...
Using username "username".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] username@site.com /path1/path2 E:\
No file matching '*.csv' found.
Success

Error actually occurred in another transfer to the same server. This process doesn't have email setup.

Searching for host...
Connecting to host...
Authenticating...
Using username "username".
Authenticating with pre-entered password.
Access denied.
Disconnected: No supported authentication methods available (server sent: publickey)
Authentication log (see session log for details):
Using username "username".
Access denied.
Authentication failed.
Error

Config for the failed job

call :transfer > C:\site\logs\transfername-Outbound-Outstanding.log:

:transfer
set datestamp=%date:~10,4%%date:~7,2%%date:~4,2%
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\site\logs\transfername-Outbound-OutstandingWinSCP_%datestamp%.log" /ini=nul ^
/command ^
"open sftp://username:password@site.com -hostkey=""ssh-dss 2048 9a:82:20:78:73:9b:b2:9b:ba:9a:da:3d:26:8d:09:6f""" ^
"cd /outbound/outstanding" ^
"lcd ""E:\""" ^
"get -delete *.csv" ^
"exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)

exit /b %WINSCP_RESULT%


Is this happening because I have multiple transfers happening on the same site?


Graeme
Guest

Re: %WINSCP_RESULT%

martin wrote:

Looks good. Can you show us an example of the log file?


The log file that is Emailed is the success email. Whereas the job that actually fails doesn't email at all. The %WINSCP_RESULT% of the failed task somehow triggers an email on the successful job.


Graeme
martin

Re: %WINSCP_RESULT%

Looks good. Can you show us an example of the log file?
devlin7

Re: %WINSCP_RESULT%

Sorry the log file should have shown as C:\logs\Outstanding.log not C:\\logs\Outstanding.log
Guest

Re: %WINSCP_RESULT%

martin wrote:

Please, show us your code/batch file.


@echo off

call :transfer > C:\\logs\Outstanding.log:

:transfer
set datestamp=%date:~10,4%%date:~7,2%%date:~4,2%
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\\logs\OutstandingWinSCP_%datestamp%.log" /ini=nul ^
/command ^
"open sftp://site -hostkey=""ssh-dss 2048 code""" ^
"cd /outstanding" ^
"lcd ""E:\Outstanding""" ^
"get -delete *.csv" ^
"exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
c:\Blat\Blat.exe C:\\logs\Outstanding.log -to my@email.com -f FTP_donotreply@email.com -server x.x.x.x >nul
)

exit /b %WINSCP_RESULT%
martin

Re: %WINSCP_RESULT%

Please, show us your code/batch file.
Guest

Re: %WINSCP_RESULT%

Sorry forgot to state that each transfer has a different log file so there is no chance that the wrong log is being sent.
devlin7

%WINSCP_RESULT%

Hi,

Firstly, may I say what a great product and really easy to use and script!!!!
I have three scripts that use the same physical site. Each script does different things either putting or getting files.

I am using the %WINSCP_RESULT% error mode to generate an Email to say there is an issue, the email contains a copy of the log file during the transfer. The weird thing is that the log file sent always shows success, so in theory the Email shouldn't have been sent.

When I looked at the logs for the three jobs, I can see that one of the log files actually has an error. What I suspect is that two connections occur to the same site at the same time. The remote site restricts to one logon and therefore causes an error. While this may cause an error to occur in TRANSFER A, the error check in TRANSFER B is detecting the error also.

I am just wondering what is the best way to handle this. Do I need to create three separate sites? How do I separate the tasks so that one error doesn't show in another task.


Regards