问题
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:
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) 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;
}
}
来源:https://stackoverflow.com/questions/45606880/is-it-possible-to-create-sftpnot-ftp-user-using-c-if-it-is-then-how