简体   繁体   English

是否可以使用 c# 创建 SFTP(非 FTP)用户? 如果是那又如何?

[英]Is it possible to create SFTP(Not FTP) user using c#? If it is then how?

Creating SFTP(Not FTP) user account through c# code.通过 C# 代码创建 SFTP(非 FTP)用户帐户。 Is this possible to create sftp users by my code?这可以通过我的代码创建 sftp 用户吗? I'm using bitvise SSH server as my sftp server, and filezilla server as my ftp server, now I want to create different users for my different employees so that they all would have access of different folders on my server and could not be able to access each others path (folders).Can anyone have some idea of user creation in sftp by c# code?我使用 bitvise SSH 服务器作为我的 sftp 服务器,使用 filezilla 服务器作为我的 ftp 服务器,现在我想为我的不同员工创建不同的用户,以便他们都可以访问我服务器上的不同文件夹并且无法访问彼此的路径(文件夹)。任何人都可以通过 c# 代码在 sftp 中创建用户吗?

1) For make windows bitvise ssh server Account 1) 为使 windows bitvise ssh 服务器帐户

public static int Main(string[] args)
    {
        try
        {
            var cfg = new CBssCfg726("BssCfg726.BssCfg726");
            cfg.SetSite("Bitvise SSH Server");
            cfg.LockServerSettings();
            cfg.LoadServerSettings();

            cfg.settings.access.winAccountsEx.@new.winDomain = "Domain_Name";
            cfg.settings.access.winAccountsEx.@new.winAccount = "Account_Name";
            cfg.settings.access.winAccountsEx.@new.loginAllowed = cfg.DefaultYesNo.yes;
            cfg.settings.access.winAccountsEx.@new.xfer.mountPointsEx.Clear();
            cfg.settings.access.winAccountsEx.@new.xfer.mountPointsEx.@new.realRootPath = "C:\\Sftp\\User";
            cfg.settings.access.winAccountsEx.@new.xfer.mountPointsEx.NewCommit();
            cfg.settings.access.winAccountsEx.NewCommit();
            cfg.UnlockServerSettings();
            cfg.SaveServerSettings();


            return 0;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

2) For make virtual bitvise ssh server account 2) 用于制作虚拟 bitvise ssh 服务器帐户

private void AssignPowerSchoolCredentials()
    {
        try
        {
            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 = "Folder_path";
            cfg.settings.access.virtAccountsEx.@new.xfer.mountPointsEx.NewCommit();
            cfg.settings.access.virtAccountsEx.@new.fwding.srvSideC2S.ipv4Ex.NewCommit();
            cfg.settings.access.virtAccountsEx.NewCommit();
            cfg.SaveServerSettings();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

I am trying to create sftp virtual account through asp.net c# code want to use this code but I am not able to understand what CBssCfg726 is? 我正在尝试通过asp.net创建sftp虚拟帐户c#代码要使用此代码,但我无法理解CBssCfg726是什么? I know BssCfg726.BssCfg726 is reference mentioned in bitvise scriptable configuration. 我知道bitvise可脚本化配置中提到了BssCfg726.BssCfg726。 Do I need Powershell in my c# code? 我的C#代码中需要Powershell吗? can you please tell me what CBssCfg726 is? 你能告诉我什么是CBssCfg726吗? Thanks. 谢谢。

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

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