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.

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)


Topic review


Re: Scripting in Powershell

thanks worked like a charm !


Re: Scripting in Powershell

Thank You for your reply,

i will try it as soon as i am home.


Re: Scripting in Powershell

The winscp.exe is a GUI application. PowerShell does not seem to wait for GUI application to exit before proceeding to the next comment. So the $LASTEXITCODE cannot contain the exit code as the application has not exited yet. Use instead, what is a console application.

Scripting in Powershell


I’m not sure if this is a Bug or I am missing something here. But maybe some could help me with my problem. I like to script and FTP Transfer from Powershell. So far everything works fine but not the exit codes.

For a small test I made 2 commad scripts one that works and one that will fail. When I do let them run from batch the exit codes return fine.

winscp.exe /console /script=test1.txt /log=ftp.log
ErrorLevel 0

winscp.exe /console /script=test2.txt /log=ftp.log
ErrorLevel 1

Press any key to continue . . .

But from Powershell I always get an “0” as return code.


Code of powershellscript:

.\winscp.exe /console /script=test1.txt /log=ftp.log

.\winscp.exe /console /script=test2.txt /log=ftp.log

ftp.log shows following line:
. 2014-01-15 12:24:51.561 Script: Failed
. 2014-01-15 12:24:51.561 Script: Exit code: 1
. 2014-01-15 12:24:51.561 Disconnected from server
< 2014-01-15 12:24:51.567 226 Closing data connection

Exit Codes from Powershell:
i tried by myself with ping and the sc command. On both the exit codes worked.
Has anyone got this working on WinSCP or does have an idea how to sovle this. (i don't want to use batch)