Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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?
nyhack56

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>