Ejaz
Ejaz

Reputation: 1632

How to place unix commands - copy files from Windows to Unix directory/ Unix to Windows in VBScript?

I am not sure how to place the Unix commands in a VBScript file.

I am trying to write a code in VBScript where we can copy our files from our Windows folder to Unix directory.

Here writing files in the our Unix directory requires username and password.

I explored and found that we can use SCP command this way to copy files:

scp d:/folders/hello.txt /abc_st/batchrepo/inbox
# I am still exploring for copying files from Unix to Windows

And for Username/Password, I found that we can use sshpass command like below before scp command:

sshpass -p "your password" 
# I still have to explore on this as I cant see the place for username.

Could someone please suggest how can I place these commands in a VBScript file.

I'll be placing this VBScript into an HTML file. Thanks.

Upvotes: 0

Views: 2136

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200503

VBScript doesn't support SSH by itself, so you need some kind of scp utility for copying files from a Windows host to a Unix host, for instance pscp.exe from the PuTTY suite, or the ssh package in Cygwin.

Assuming you're using pscp.exe you can run the client by shelling out like this:

Set sh = CreateObject("WScript.Shell")
sh.Run "C:\path\to\pscp.exe -pw PASS D:\folders\hello.txt unixhost:/abc_st/batchrepo/inbox", 0, True

Make sure to quote paths if they contain spaces:

Function qq(str) : qq = Chr(34) & str & Chr(34) : End Function

Set sh = CreateObject("WScript.Shell")
sh.Run qq("C:\path\to\pscp.exe") & " -pw PASS " & qq("D:\folders\hello.txt") _
  & " unixhost:/abc_st/batchrepo/inbox", 0, True

Upvotes: 1

Related Questions