简体   繁体   中英

Create SFTP user programmatically using c#

I have been using windows server 2012 R2 and I have bitvise SSH for SFTP and I want to create SFTP user programmatically in my application.

What I am thinking to do is When any user signup into the application then application will create a new folder and SFTP credentials for a newly created folder.So each user can access their SFTP credentials for uploading their files in their associated folder.

I can find the solution to create FTP users dynamically but I want to create SFTP user.

Question: Is it possible to create SFTP user using c#? If it is then how?

You can create SFPT user using C# like:

var cfg = new CBssCfg726("BssCfg726.BssCfg726");

cfg.SetSite("Bitvise SSH Server");

cfg.LoadServerSettings();


cfg.settings.access.virtAccountsEx.@new.virtAccount ="Virtual Account Name";
cfg.settings.access.virtAccountsEx.@new.virtPassword.Set("Password");
cfg.settings.access.virtAccountsEx.@new.group = "Virtual Users";

//if already virtAccountsEx then first delete... 
for (uint i = 0; i < cfg.settings.access.virtAccountsEx.count; i++) {
    if (cfg.settings.access.virtAccountsEx.GetItem(i).virtAccount == "Virtual Account Name") {
        cfg.settings.access.virtAccountsEx.Erase(i);
    }
}
cfg.settings.access.virtAccountsEx.@new.fwding.srvSideC2S.ipv4Ex.@new.targetHost = "127.0.0.1";
cfg.settings.access.virtAccountsEx.@new.fwding.srvSideC2S.ipv4Ex.@new.targetPort = 80;
cfg.settings.access.virtAccountsEx.@new.fwding.srvSideC2S.ipv4Ex.@new.proxyProfile = "Default";
cfg.settings.access.virtAccountsEx.@new.loginAllowed = cfg.DefaultYesNo.yes;
cfg.settings.access.virtAccountsEx.@new.xfer.mountPointsEx.Clear();
cfg.settings.access.virtAccountsEx.@new.xfer.mountPointsEx.@new.sfsMountPath = "/";
cfg.settings.access.virtAccountsEx.@new.xfer.mountPointsEx.@new.realRootPath = "Path to folder";
cfg.settings.access.virtAccountsEx.@new.xfer.mountPointsEx.NewCommit();
cfg.settings.access.virtAccountsEx.@new.fwding.srvSideC2S.ipv4Ex.NewCommit();
cfg.settings.access.virtAccountsEx.NewCommit();
cfg.SaveServerSettings();

So what's this CBssCfg726 in above code? I am trying to implement this functionality in asp.net core i have read bitvise scriptable configuration as well but still not there. do I need powershell code in c#?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM