Topic ".NET: Mask to get today's file using ListDirectory method"

Author Message
Suresh
[View user's profile]

Joined: 2013-10-02
Posts: 5
Location: Malaysia
Hi,

I am currently developing a VB.NET application and I wanted to list out all txt file today’s file available in SFTP folder. The application uses Winscp.dll (version 5.0.6.0).

I am passing *.txt along with the sftp path to ListDirectory method

Example: /Test/*.txt

It downloads all files available in the /Test/ folder with .txt extension, then I am looping through each file and checking the file date time and filtering today’s file.

I found there is a Mask feature where we can specify the date time.

Ref: http://winscp.net/eng/docs/file_mask

>yyyy-mm-dd[ hh:mm[:ss]]
Matches files modified the last time after the date or time (i.e. “newer than”).
>2012-01-01,>2012-02-29 08:47



But when I pass the File Mask to List Directory method, it is not supported.

Code:
/Test/*.txt>2014-02-21


I believe I am missing some points here, please help.


Code Snippet

Code:
Imports WinSCP

Try

   Dim sessionOptions As New SessionOptions
   With sessionOptions
        .Protocol = Protocol.Sftp
        .HostName = HostName
        .PortNumber = PortNumber
        .UserName = UserName
        .Password = Password
        .SshHostKey = SSHHostKey
    End With
         
   Using session As Session = New Session
      session.Open(sessionOptions)
       
             
      Dim directory As RemoteDirectoryInfo = session.ListDirectory("/Test/*.txt>2014-02-21")
      ...
       

   End Using
             
Catch e As Exception
     WriteInLogFile("Error : " & e.Message.ToString)
End Try



WinSCP

WinSCP 5.0.6 (Build 2074)

Kindly note that I don’t want to download the file.

Thanks

Suresh
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Suresh wrote:
But when I pass the File Mask to List Directory method, it is not supported.

That's correct, the Session.ListDirectory does not support file masks. You need to filter resulting file list yourself.
Suresh
[View user's profile]

Joined: 2013-10-02
Posts: 5
Location: Malaysia
prikryl wrote:
Suresh wrote:
But when I pass the File Mask to List Directory method, it is not supported.

That's correct, the Session.ListDirectory does not support file masks. You need to filter resulting file list yourself.


Hi,

Thank you for your response.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
I have added an example:
http://winscp.net/eng/docs/library_example_listing_files_matching_wildcard
Though it's for PowerShell only.
Suresh
[View user's profile]

Joined: 2013-10-02
Posts: 5
Location: Malaysia
prikryl wrote:
I have added an example:
http://winscp.net/eng/docs/library_example_listing_files_matching_wildcard
Though it's for PowerShell only.


Thank you for your reply. As I informed I am looping through all files and filtering.

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