是否可以使用c#创建SFTP(非FTP)用户?如果是的话该怎么办? [英] Is it possible to create SFTP(Not FTP) user using c#? If it is then how?

查看:250
本文介绍了是否可以使用c#创建SFTP(非FTP)用户?如果是的话该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过c#代码创建SFTP(非FTP)用户帐户. 是否可以通过我的代码创建sftp用户?我将bitvise SSH服务器用作sftp服务器,并将filezilla服务器用作ftp服务器,现在我想为我的不同员工创建不同的用户,以便他们都可以访问我的服务器上的不同文件夹,并且无法可以访问彼此的路径(文件夹).有人可以通过c#代码在sftp中创建用户吗?

Creating SFTP(Not FTP) user account through c# code. Is this possible to create sftp users by my code? 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?

推荐答案

1)对于使Windows咬SSH服务器帐户

1) For make windows bitvise ssh server Account

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)用于制作虚拟bitvise ssh服务器帐户

2) For make virtual bitvise ssh server account

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;
        }
    }

这篇关于是否可以使用c#创建SFTP(非FTP)用户?如果是的话该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆