Topic "Help with VB script"

Author Message
Guest




Hi,

I'm a total newbie at this and now my way around VB, I would like to have a script where I drop a folder, I extract the folder name and connect to a NAS where I want it to move this specific folder from one place to another with MV.

I started to make a test, but I get an error on row exec.StdIn.Write(
Code:

Set objArgs = WScript.Arguments
'WScript.Echo WScript.Arguments.Count

myFolder = Split(objArgs(0),"\")
intIndex = Ubound(myFolder)
WScript.Echo myFolder(intIndex)

Set shell = WScript.CreateObject("WScript.Shell")
'run (make it log to XML)
shell.Exec("""C:\Program Files (x86)\WinSCP\WinSCP.exe""")
' feed the commands
exec.StdIn.Write("option batch abort\n" + "open Nas\n" +"ls /share/HDA_DATA/Test\n" +"exit\n")

'wait until it finishes and collect its output
StdOut.ReadAll()
'optionally print the output
WScript.Echo(output)

 


Suggestions how I can get this to work ?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
You need to store the result of shell.Exec call to variable exec taht you are using line below:
Code:
var exec = shell.Exec("""C:\Program Files (x86)\WinSCP\WinSCP.exe""")
exec.StdIn.Write("option batch abort\n" + "open Nas\n" +"ls /share/HDA_DATA/Test\n" +"exit\n")


See documentation:
https://winscp.net/eng/docs/guide_automation_advanced#inout
Guest




Thanks !

Code:
Set objArgs = WScript.Arguments
'WScript.Echo WScript.Arguments.Count

myFolder = Split(objArgs(0),"\")
intIndex = Ubound(myFolder)
WScript.Echo myFolder(intIndex)

Set shell = WScript.CreateObject("WScript.Shell")
'run (make it log to XML)
set exec = shell.Exec("""C:\Program Files\WinSCP\WinSCP.exe""")
' feed the commands
exec.StdIn.Write("option batch abort\n" + "open Nas\n" +"ls /share/HDA_DATA/'test\n" +"exit\n")

'wait until it finishes and collect its output
set output = exec.StdOut.ReadAll()
'optionally print the output
WScript.Echo(output)


Now it starts winscp, but it does not login and do the ls part. and logging in manually and quit Winscp gives me Objext required: '[string:""]' on set output row.

Suggestions ?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
Turn on session logging to file and inspect the log. If you do not find anything, post it here.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License