.net - FTPS (FTP over SSL) in C# -
i need guidance. need develop customizable ftp in c# should configured using app.config file. also, ftp should push data server client again depends on config file.
i appreciate if can guide, if there api or other useful suggestion, or move me in right direction.
you can use ftpwebrequest; however, low level. there higher-level class webclient, requires less code many scenarios; however, doesn't support ftp/ssl default. fortunately, can make webclient
work ftp/ssl registering own prefix:
private void registerftps() { webrequest.registerprefix("ftps", new ftpswebrequestcreator()); } private sealed class ftpswebrequestcreator : iwebrequestcreate { public webrequest create(uri uri) { ftpwebrequest webrequest = (ftpwebrequest)webrequest.create(uri.absoluteuri.remove(3, 1)); // removes "s" in "ftps://". webrequest.enablessl = true; return webrequest; } }
once this, can use webclient
normal, except uris start "ftps://" instead of "ftp://". 1 caveat have specify method
parameter, since there won't default one. e.g.
using (var webclient = new webclient()) { // note here second parameter can't null. webclient.uploadfileasync(uploaduri, webrequestmethods.ftp.uploadfile, filename, state); }
Comments
Post a Comment