Check For File

Advertisement

ansonee
Joined:
Posts:
5
Location:
Minneapolis, MN USA

Check For File

I have found a ton of posts that instruct you how to check for the existence of a file, but every example I have found is for using WinSCP.com - I have yet to find an example that demonstrates how to use WinSCP.exe and how to check for a file with a mask.

Is there someplace I can find an example of this?

This is my current script:

SET REMOTE_PATH = /out/extract_CES_SAE_v3_p0019478fq5n*.txt.pgp

open sftp://p00xxxxxxxxxxxxxx@st.concursolutions.com/ -hostkey="ssh-rsa 2048 wbxxxxxxxxxxxxxxxxxxxxxxxxxxx="
option failonnomatch on
ls %REMOTE_PATH%

#lcd "C:\Concur Files\Incoming\Daily SAE File"

#get -resumesupport=off -delete "./out/extract_CES_SAE_v3_p0019478fq5n*.txt.pgp"
# Your command 2

exit

if %ERRORLEVEL% neq 0 goto error

echo file %REMOTE_PATH% exists
lcd "C:\Concur Files\Incoming\Daily SAE File"
get -resumesupport=off -delete "./out/extract_CES_SAE_v3_p0019478fq5n*.txt.pgp"
exit /b 0

:error
echo ERROR or file %REOMTE_PATH% not exists
exit /b1

# Execute the script using a command like:
# "C:\Program Files (x86)\WinSCP\WinSCP.exe" /log="C:\writable\path\to\log\WinSCP.log" /ini=nul /script="C:\path\to\script\script.txt"

Any help would be appreciated...

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,506
Location:
Prague, Czechia

Re: Check For File

Why do you want to use winscp.exe?
From a batch file, you should use winscp.com.
See https://winscp.net/eng/docs/executables
Though for purposes of your question, it actually does not matter.

Also your code in unclear. Is that a single file? You cannot mix WinSCP and cmd.exe (Windows) commands in on file like this.

Reply with quote

ansonee1
Guest

Check File Existence With Winscp.exe

I'm using winscp.exe because it's a line command within an SSIS package in an execute command task.

And I actually already have a script that runs winscp.exe just fine with no problems.

I just want to check for a file. My script file runs fine, so when you say you can't mix it...yo actually can. I've been doing it for months.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,506
Location:
Prague, Czechia

Re: Check File Existence With Winscp.exe

Does your answer mean that the whole code in your post is in a single script file? And that you call that script using WinSCP.exe /script=...?

Then the code stops on the first exit command. And the rest is never even considered.
Had it been, it would fail, as those are not valid WinSCP commands.

Again, your code mixes WinSCP and Windows batch file commands. That's not possible.

If you want to use a Windows batch file, you need to call that batch file (not WinSCP) from SSIS. And the batch file has to call WinSCP in turn (passing it the commands using a separate script file - or on command line using /command switch).

Actually, you can see that in the article, which I assume you based your script on:
https://winscp.net/eng/docs/script_checking_file_existence#scripting

For another example, see:
https://winscp.net/eng/docs/guide_automation#results

Reply with quote

ansonee1
Guest

I'm not using a batch file - I'm executing a script file.

I've taken out the WinSCP.com commands. My script file runs just fine when running from SSIS.

Again, I'm not using winscp.com - I want to use WinSCP.exe since that is what has been working all these months. The examples I've found are all for WinSCP.com

I cannot find any options for WinSCP.exe to check for a file.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,506
Location:
Prague, Czechia

ansonee1 wrote:

I'm not using a batch file - I'm executing a script file.
Sorry, but you really need to read my answers carefully. You have a conceptual misunderstanding of what you are doing. Your problem is that you are not using a batch file. Because you need to. Some of the commands in your WinsCP script are not WinSCP commands. Those are batch file commands. They won't ever work in WinSCP script.

Again, I'm not using winscp.com - I want to use WinSCP.exe since that is what has been working all these months. The examples I've found are all for WinSCP.com
WinSCP.exe and WinSCP.com have the same commands. Though if you use WinSCP.exe you will have troubles with debugging, as it's not a console application. Use WinSCP.com.
Read the link in my first answer to understand.

If you are not willing to take my advises, please do not even respond. It's a waste of a time for both of us.

Reply with quote

Advertisement

You can post new topics in this forum