Topic "ListDirectory with file pattern"

Author Message
Vara04
[View user's profile]

Joined: 2012-05-26
Posts: 5
Location: France
Hello,

How can I list on remote FTP server : "/mydir/*.csv"
It works fine with "/mydir" but not with file pattern :-\

Any solution ?

ok I can list all files and after filter them but if there is a better solution Wink
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
It is not supported and most protocols do not support filtering listing on the server side anyway.
So do it yourself.
_________________
Martin Prikryl
Vara04
[View user's profile]

Joined: 2012-05-26
Posts: 5
Location: France
Ok thanks
_________________
Chris
Vara04
[View user's profile]

Joined: 2012-05-26
Posts: 5
Location: France
If I can help :

This is how it can be done :

Regexp construction pattern : see PJ

Loop on file return by ListDirectory with a new parameter pattern

Code:

RemoteDirectoryInfo v_RemoteDirectoryInfo = session.ListDirectory(path);
Regex v_Regex = FTPClientBeanCommandFTP.FindFilesPatternToRegex.Convert(pattern);
List<RemoteFileInfo> v_ListFile = new List<RemoteFileInfo>();
foreach (RemoteFileInfo v_RemoteFileInfo in v_RemoteDirectoryInfo.Files)
{
   if ((!v_RemoteFileInfo.IsDirectory)
      && (v_Regex.IsMatch(v_RemoteFileInfo.Name)))
   {
      v_ListFile.Add(v_RemoteFileInfo);
   }
}

// This can not be done because ".Files" is read only
v_RemoteDirectoryInfo.Files.Clear();
foreach (RemoteFileInfo v_RemoteFileInfo in v_ListFile)
{
   v_RemoteDirectoryInfo.Files.Add(v_RemoteFileInfo);
}


So it can be call like this :
RemoteDirectoryInfo v_RemoteDirectoryInfo = session.ListDirectory("/TestFTP", "*.CSV");
RegEx.txt (1.52 KB) [Download]

Description: (none)

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