Topic "Using ListDirectory in VBScript"

Author Message
[View user's profile]

Joined: 2014-06-27
Posts: 1

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.



<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

' Disconnect, clean up

[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24755
Location: Prague, Czechia
I'm not VB expert, but don't you need to use Set?

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

As per examples here:

Also are you sure that the ListDirectory succeeded? Did you check a log file?
Martin Prikryl
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24755
Location: Prague, Czechia
I've put together working example for VBScript:

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!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License