using vbs to connect sftp and use "put" command

Advertisement

FrankT
Joined:
Posts:
3

using vbs to connect sftp and use "put" command

Hi! I am new to to scripting and WinSCP. I need to create a script to connect to a ftp service and copy files to it. I've tied the following with no success. Please help!!!

Dim wshShell
Dim sftpcmd
Set wshShell = WScript.CreateObject("WScript.Shell")


sftpcmd = "winscp /console /command " & """open sftp://nstcn61:password@10.10.1.100 -hostkey= ssh-rsa 1024 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX" & "put c:\sysaudit\*.*" & "close""" & " " & """exit"

wshShell.Run(sftpcmd),1,true

wscript.sleep(20000) 'wait for 20 seconds until sftp is done




Any help would be appreciated.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

Re: using vbs to connect sftp and use "put" command

You have quotes all wrong. I do not know VBS, but I guess right format is:
sftpcmd = "winscp /console /command ""open sftp://nstcn61:password@10.10.1.100 -hostkey=""""ssh-rsa 1024 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX"""""" ""put c:\sysaudit\*.*"" ""close"" ""exit"""

Read also:
https://winscp.net/eng/docs/commandline#syntax

Of course the XX:XX:XX... has to be replaces with actual fingerprint.

Reply with quote

FrankT
Joined:
Posts:
3

Re: using vbs to connect sftp and use "put" command

martin wrote:

You have quotes all wrong. I do not know VBS, but I guess right format is:
sftpcmd = "winscp /console /command ""open sftp://nstcn61:password@10.10.1.100 -hostkey=""""ssh-rsa 1024 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX"""""" ""put c:\sysaudit\*.*"" ""close"" ""exit"""

Read also:
https://winscp.net/eng/docs/commandline#syntax

Of course the XX:XX:XX... has to be replaces with actual fingerprint.



WOW!!! I love you, man!!! You just fixed a problem for me that has been a thorn in my side for days!!! Thank you, thank you, thank you!!!

Reply with quote

FrankT
Joined:
Posts:
3

OK, I have one last problem with this script; In the console, I am getting the following msg.

"The server's host key was not found in the cache. You have no guarantee that the server is the computer you think it is......If you trust this host, press Yes. To connect without adding host key to the cache, press No. To abandon the connection press Cancel.
Continue connecting and add host key to the cache?
(Y)es, (N)o, C(a)ncel, (C)opy Key:
"

I need it to pass on the key automatically. Any insite on how to do this with the example you provided?

Thanks!!!

Reply with quote

Advertisement

You can post new topics in this forum