Topic "Execute WinSCP from a batch file"

Author Message
Quickdeveloper

Guest


Hi

I want to execute winscp script from a batch file.

Assume the following contents are in C:\MYFILE.BAT

Code:

echo " OPENING THE SESSION "
winscp.com /console /command:"open xyz:abc@ipaddress"
echo "CONNECTED TO THE VM "

REM   delete old files
rm file1.tar



when i run C:\>MYFILE.BAT , i am able to connect to unix vm, however it goes into shell mode and second command (deleting file1.tar won't get executed). do we need to give any other parameter?


I know we can execute batchfile itself from winscp directory (eg: winscp.com /script:filename.bat) but in that case i can't check errors with if/ else conditions in batch file since winscp doesn't recognise the if/else.

Any suggestions please? i don't want to use xml logging as it looks too complicated for my use.


Thanks
Advertisements
quickdeveloper
[View user's profile]

Joined: 2012-04-25
Posts: 2
Please also note that i am using winscp.com to redirect the output to a text file.

The only other option would be to open a new winscp session in each command line of batch file which involves more cost.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
You have to put WinSCP command to a separate script file.
Please read scripting guide:
https://winscp.net/eng/docs/guide_automation
_________________
Martin Prikryl
quickdeveloper
[View user's profile]

Joined: 2012-04-25
Posts: 2
Thanks Martin,i checked it.

I have used C# with WinSCP dll and accomplished the task.

I realized it's much easier and faster that way in terms of exception handling Very Happy


Thanks!
atchere

Guest


prikryl wrote:
You have to put WinSCP command to a separate script file.
Please read scripting guide:
https://winscp.net/eng/docs/guide_automation

Question I am having trouble getting WINSCP to take a password in the batch mode what is the correct syntex to make this happen

atc
Prasadhello

Guest


I am trying to run winscp from bat file and with xp_cmdshell in sql server. However when I run it keeps running forever. I have put exit in bat file. Anybody aware of this issue?

Also is there any way to capture winscp dir results in sql server table or like normal result set instead of XML.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Prasadhello wrote:
I am trying to run winscp from bat file and with xp_cmdshell in sql server. However when I run it keeps running forever. I have put exit in bat file. Anybody aware of this issue?

Please start a new thread and attach a full log file showing the problem (using the latest version of WinSCP).

To generate log file, use /log=path_to_log_file command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you may email it to me. You will find my address (if you log in) in my forum profile. Please include link back to this topic in your email. Also note in this topic that you have emailed the log.
Mahmoud

Guest


Hi all,

I did the following batch file to send file to sftp server, but the put command (or any commands) after sftp session opeded didn't work:

cd C:\Program Files\prog1\output1

WinSCP.exe username@x.x.x.x/example/test

put %file%

close

exit

can any one help?

thnaks
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Mahmoud wrote:
I did the following batch file to send file to sftp server, but the put command (or any commands) after sftp session opeded didn't work:

You are obviously combining Windows and WinSCP commands in a single file. You cannot do this.
Read https://winscp.net/eng/docs/guide_automation
_________________
Martin Prikryl
Fairfielder
[View user's profile]

Joined: 2015-12-31
Posts: 2
prikryl wrote:
Mahmoud wrote:
I did the following batch file to send file to sftp server, but the put command (or any commands) after sftp session opeded didn't work:

You are obviously combining Windows and WinSCP commands in a single file. You cannot do this.
Read https://winscp.net/eng/docs/guide_automation


I don't understand. On the following page it shows this example batch file, which combines WinSCP and Windows commands:
https://winscp.net/eng/docs/guide_automation

Here's the example batch file:

winscp.com /script=example.txt
if %ERRORLEVEL% neq 0 goto error

echo Success
sendmail.exe -t < success_mail.txt
exit 0

:error
echo Error!
sendmail.exe -t < error_mail.txt
exit 1
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Fairfielder wrote:
I don't understand. On the following page it shows this example batch file, which combines WinSCP and Windows commands:
https://winscp.net/eng/docs/guide_automation

There's no WinSCP command it that batch file. The WinSCP commands are in example.txt.
Madhu

Guest


Hi

I am trying to get file using SFTP. My set up was authentication with public key Passphrase.

Here is my scrip file name getfile.txt
open xxxxxx (site already stored with host name, port and username)
passphrase
get *.txt to c:\*.txt
Close
exit

Created download.bat file as follows:
@echo off
winscp.com /script=getfile.txt

both the files are saved at WinSCP folder.

When download.bat file run, the script did not take Passphrase as per second line and come out without further execution.
Can anyone help how input Passphrase.

Thanks
Madhu
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Use the -passphrase switch:

open xxxxxx -passphrase=mypassphrase

See https://winscp.net/eng/docs/scriptcommand_open

Note that it is generally not recommended to use stored site in script.
See https://winscp.net/eng/docs/scripting#configuration
Guest




Prasadhello wrote:
I am trying to run winscp from bat file and with xp_cmdshell in sql server. However when I run it keeps running forever. I have put exit in bat file. Anybody aware of this issue?

Also is there any way to capture winscp dir results in sql server table or like normal result set instead of XML.


Did you ever resolve this issue? I am experiencing the same issue - no log files to give me a hint at the problem.

How did you resolve this issue??
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Quote:
Did you ever resolve this issue? I am experiencing the same issue - no log files to give me a hint at the problem.

What did you try to get the logs?
Guest




martin wrote:
Quote:
Did you ever resolve this issue? I am experiencing the same issue - no log files to give me a hint at the problem.

What did you try to get the logs?


Nothing was in the logs. My xp_cmdshell query just runs...the same issue you reported experiencing.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
I'm sorry, but I do not understand your response.

I have asked: What did you try to get the logs?
_________________
Martin Prikryl
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