简体   繁体   English

使用 C# 以编程方式创建 SFTP 用户

[英]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.我一直在使用 Windows Server 2012 R2,我有用于 SFTP 的 bitvise SSH,我想在我的应用程序中以编程方式创建 SFTP 用户。

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.我想做的是当任何用户注册到应用程序时,应用程序将为新创建的文件夹创建一个新文件夹和 SFTP 凭据。因此每个用户都可以访问他们的 SFTP 凭据,以便将他们的文件上传到他们的关联文件夹中。

I can find the solution to create FTP users dynamically but I want to create SFTP user.我可以找到动态创建 FTP 用户的解决方案,但我想创建 SFTP 用户。

Question: Is it possible to create SFTP user using c#?问题:是否可以使用 C# 创建 SFTP 用户? If it is then how?如果是那么怎么办?

You can create SFPT user using C# like:您可以使用 C# 创建 SFPT 用户,例如:

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? 那么以上代码中的CBssCfg726是什么? I am trying to implement this functionality in asp.net core i have read bitvise scriptable configuration as well but still not there. 我试图在asp.net核心中实现此功能,我也阅读了bitvise可编写脚本的配置,但仍然不了解。 do I need powershell code in c#? 我需要在C#中使用Powershell代码吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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