c# - SSH.Net library and use of wild card -


i need login sftp ssh.net , delete files in folder, seem ssh.net not support wild card. true? there way fix it? here code.

using (sftpclient sftpclient = new sftpclient(server, port, username, password)) {     foreach (var d in sftpclient.connectioninfo.encryptions.where(p => p.key != "blowfish-cbc").tolist())     {         sftpclient.connectioninfo.encryptions.remove(d.key);     }      sftpclient.connect();     sftpclient.deletefile("/outgoing/*.*");     sftpclient.disconnect(); } 

i haven't had luck wildcards using library, either. ended creating extension method (simplistic):

public static ienumerable<sftpfile> listdirectorywc(this sftpclient client, string pattern, func<sftpfile,bool> includetest=null) {     string directoryname = (pattern[0] == '/' ? "" : "/") + pattern.substring(0, pattern.lastindexof('/'));     string regexpattern = pattern.substring(pattern.lastindexof('/') + 1)             .replace(".", "\\.")             .replace("*", ".*")             .replace("?", ".");     regex reg = new regex('^' + regexpattern + '$');      var results = client.listdirectory(string.isnullorempty(directoryname) ? "/" : directoryname)         .where(e => reg.ismatch(e.name) && (includetest == null || includetest(e)));     return results; }  public static void deletefilewc(this sftpclient client, string pattern, func<sftpfile,bool> includetest=null) {     foreach(var file in client.listdirectorywc(pattern, includetest))     {         file.delete();     } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -