0

I would like to transfer one file via pscp using wscript and this code just don't work. It doesn't throw any error, but it won't transfer file or make output either.

Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Exec "C:\scripts\putty\pscp.exe -pw password C:\file_to_transfer.txt user@server.cz:/directory  2>> C:\Log_file.txt"

thanks for help....

1 Answers1

0

You need a shell for shell features (e.g. redirection). So prepend "%comspec% /c " to your command.

Do you know that .Exec allows to read the StdOut/StdErr of the called process?

Evidence:

>> f = "c:\temp\pscp.log"
>> c = "pscp -pw pword -ls user@host:/home"
>> set s = CreateObject("WScript.Shell")
>> WScript.Echo s.Run(c & " > " & f, 0, True)
>> WScript.Echo s.Run( "%comspec% /c " & c & " > " & f, 0, True)
>> WScript.Echo goFS.OpenTextFile(f).ReadAll()
>> WScript.Echo s.Exec(c).Stdout.ReadAll()
>>
1   <-- no shell/%comspec%, no luck
0   <-- it did not fail
Listing directory /home  <-- .Run did work with shell
drwxr-xr-x    5 root     root         4096 Feb 22  2011 .
...

Listing directory /home <-- .Exec().Stdout.ReadAll() works
drwxr-xr-x    5 root     root         4096 Feb 22  2011 .
...
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • thanks, but it doesn't work for me. Throw error on line 6 char 1 - required goFS object. – user3493540 Apr 03 '14 at 19:53
  • @user3493540 - it's *evidence* not 'ready to copy & paste code'. Please ask yourself what object has an .OpenTextFile method. Did you try the `%comspec% /c` addition? – Ekkehard.Horner Apr 03 '14 at 20:01
  • This is my first task in scripting so I quite have no idea what I'm doing. I would be happy if I could just transfer that file over pscp for begining... – user3493540 Apr 04 '14 at 07:19