Post a reply

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

martin

Ok, then indeed the code linked by @Mister H is helpful.
Or see similar Using VBA to run WinSCP script or Microsoft's take on the topic: Determine when a shelled process ends

But! WinSCP does not return "SFTP codes". It returns 0 for success and 1 for error.
See How do I know that script completed successfully?

Once you check the exit code only, you do not need the batch file at all. It becomes unnecessary overhead/complication. Run winscp.com directly and check its exit code.
Hanmacaio

@Mister H: Bro, it worked, thank you so much! I must test this now a few times and set some timer to run the script automatically, but this I can do on my own.

Appreciate!
Guest

Hello!
Uh... and how do I get the value in a GUI? What I mean is, It must appear in a Interface (like a pop up or modal). I'm trying to install the ".dll" from WinSCP inside the VBA, but it's not working and I don't know why.
There is this %ERRORLEVEL% thing on the script, can I use it as an object and get his value on VBA? I know that this might be an WinSCP forum, but I think it is relatable.

Anyways, thx for the attention!
Mister H

When you run your batch file if the server is up and the script completes successfully it should write/echo "Success". If the server is down or the script fails to execute properly then the batch file will output "Error". You need to have your VBA program check standard error/output from the batch file for either "Success" or "Error". If you just want to check to see if the server is online, in your script you can just run the open command followed by the exit command. That will test connectivity to the server to see if it is up.
Hanmacaio

Re: Diagnosis or Status of a service

Yes, I do know that it already checks, but I need to show that it's checking... otherwise the people that don't know that will get confused.

Let me try to explain. I need to get somehow a value from that script, that value must be a "Server check", if the server is up, then value is 0, if not up than 1, or something like that.
That value will be passed to a GUI to be shown to everyone.

I know it is kinda screwed, because WinSCP already do it by itself, but I am being asked to do it so...
martin

Re: Diagnosis or Status of a service

I do not understand what exactly do you need. Your script already checks the result of the connection and the transfer.
Hanmacaio

Diagnosis or Status of a service

Hello, I'm working on a project of automation that uses Factorytalk VBA and I was requested to consume an FTP server. Well I scripted everything and it works just fine but I am having a big trouble now... I need to get a Diagnosis of the server to check if it's online or not, like some value for me to show inside de VBA code. Is there anyway to do it?

I'll let the script down here, just in case it is needed, it's basically the script done by WinSCP, just a few changes, it is a Batch (.bat) file:
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\Users\Administrador\AppData\Local\Temp\CANT SHOW THIS" /ini=nul ^
  /command ^
    "open ftp:CANT SHOW THIS EITHER/" ^
    "lcd C:\Users\Public\Documents" ^
    "cd /" ^
    "put Envio" ^
    "cd /Envio" ^
    "put -delete Envio\*" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%