Using ListDirectory in VBScript

Advertisement

nyhack56
Joined:
Posts:
1

Using ListDirectory in VBScript

Hi,

I am writing a VBScript (WSF file actually) to try to use ListDirectory to list out all of the files in the directory.

When I try to run the code below, I get an error "Object Required: WinSCP.RemoteDirecto" on the bolded line in the code, which I assume is RemoteDirectoryInfo. Is there a way I can get this to run in VBScript? I tried setting the directory variable to a CreatObject of WinSCP.RemoteDirectoryInfo, but that is not an automated class.

Can anyone point me in the right direction, or at least let me know that VBScript is not viable for ListDirectory? I tried the documentation on the WinSCP website, but they don't have a VBScript example for ListDirectory.

Any help would be appreciated.

Thanks,

Mark


<job>
<reference object="WinSCP.Session"/>
<script language="VBScript">

Option Explicit

' Setup session options
Dim sessionOptions
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
.Protocol = Protocol_Sftp
.HostName = "<my Hostname>"
.UserName = "<my Username>
.Password = "<my Password>"
.PortNumber = 22
.SshHostKeyFingerprint = "<the SSH Key>"
End With

Dim session
Set session = WScript.CreateObject("WinSCP.Session")
Dim directory
Dim fileInfo

' Connect
session.Open sessionOptions

directory = session.ListDirectory("/Inbox")

For Each fileInfo In directory.Files
Msgbox fileInfo.Name
Next

' Disconnect, clean up
session.Dispose

</script>
</job>

Reply with quote

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

Re: Using ListDirectory in VBScript

I'm not VB expert, but don't you need to use Set?

I.e. Set directory = session.ListDirectory("/Inbox")

As per examples here:
https://winscp.net/eng/docs/library_vb#error

Also are you sure that the ListDirectory succeeded? Did you check a log file?
_________________
Martin Prikryl

Reply with quote

Advertisement

You can post new topics in this forum