简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM