是否可以使用c#创建SFTP(非FTP)用户?如果是的话怎么样?

时间:2017-08-10 07:15:30

标签: c# asp.net ftp sftp filezilla

通过c#代码创建SFTP(非FTP)用户帐户。 这可以通过我的代码创建sftp用户吗?我正在使用bitvise SSH服务器作为我的sftp服务器,而filezilla服务器作为我的ftp服务器,现在我想为我的不同员工创建不同的用户,这样他们就可以访问我服务器上的不同文件夹而无法访问访问彼此的路径(文件夹)。任何人都可以通过c#代码了解sftp中的用户创建吗?

1 个答案:

答案 0 :(得分:1)

1)对于make 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)对于make virtual 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;
        }
    }