Execute WinSCP from a batch file

Advertisement

Quickdeveloper
Guest

Execute WinSCP from a batch file

Hi

I want to execute winscp script from a batch file.

Assume the following contents are in C:\MYFILE.BAT
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

Reply with quote

Advertisement

quickdeveloper
Joined:
Posts:
2

WinSCP from batch file

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.

Reply with quote

quickdeveloper
Joined:
Posts:
2

Execute WinSCP from a batch file

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 :D

Thanks!

Reply with quote

atchere
Guest

Re: Execute WinSCP from a batch file

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

Reply with quote

Advertisement

Prasadhello
Guest

Winscp from bat file

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.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Winscp from bat file

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.

Reply with quote

Mahmoud
Guest

send file to sftp server

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?

thanks

Reply with quote

Advertisement

Fairfielder
Joined:
Posts:
1

Re: send file to sftp server

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

Reply with quote

Madhu
Guest

Scripting Public key authentication passphrase

Hi

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

Here is my script 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

Reply with quote

Advertisement

Guest

Re: Winscp from bat file

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??

Reply with quote

martin
Site Admin
martin avatar

Re: Winscp from bat file

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?

Reply with quote

Guest

Re: Winscp from bat file

martin wrote:

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.

Reply with quote

martin
Site Admin
martin avatar

Re: Winscp from bat file

I'm sorry, but I do not understand your response.

I have asked: What did you try to get the logs?

Reply with quote

Advertisement

optimus
Guest

Re: Execute WinSCP from a batch file

quickdeveloper wrote:

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 :D

Thanks!
can u share the code

Reply with quote

Advertisement

You can post new topics in this forum