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

Advertisement

Suresh
Joined:
Posts:
5
Location:
Malaysia

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

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: https://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.

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

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


Code Snippet

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

Reply with quote E-mail

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
29,502
Location:
Prague, Czechia

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

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.

Reply with quote

Suresh
Joined:
Posts:
5
Location:
Malaysia

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

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

Reply with quote E-mail

Advertisement

You can post new topics in this forum