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