我们使用WinSSHD作为SFTP服务器,我想让我的ASP.NET C#Web应用程序的用户在服务器上创建一个新的虚拟帐户。 (Web应用程序的每个用户都有多个需要单独FTP帐户的合作伙伴,所以每次只手动创建它们都不方便。)每个虚拟帐户都需要有一个挂载点,以便其路径路径指向不同的物理路径。
目前我只知道如何在WinSSHD控制面板中执行此类操作。是否有某种API?
答案 0 :(得分:0)
我已经弄清楚了。我最终做了这样的事情:
// This Guid is the uuid of the coclass in WinsshdCfgManip.idl (depends on your WinSSHD version)
dynamic config = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("A3E7581A-5182-41C4-9AFD-2DFF07F06167"), server, true));
config.SetSite("WinSSHD");
config.LockWinsshdSettings();
config.LoadWinsshdSettings();
config.ProcessInstruction(@"access.virtAccounts.New.virtAccount """ + username + @"""");
config.ProcessInstruction(@"access.virtAccounts.New.virtPassword.Set """ + password + @"""");
config.ProcessInstruction(@"access.virtAccounts.New.group ""Virtual Users""");
config.ProcessInstruction(@"access.virtAccounts.New.useDefaultWinAccount false");
config.ProcessInstruction(@"access.virtAccounts.New.winDomain """ + winDomain + @"""");
config.ProcessInstruction(@"access.virtAccounts.New.winAccount """ + winAccount + @"""");
config.ProcessInstruction(@"access.virtAccounts.New.loginAllowed yes");
config.ProcessInstruction(@"access.virtAccounts.New.passwordAuth required");
config.ProcessInstruction(@"access.virtAccounts.New.permitRemoteAdmin no");
config.ProcessInstruction(@"access.virtAccounts.New.mapRemoteHomeDir no");
config.ProcessInstruction(@"access.virtAccounts.New.allowSessionJobBreakaway no");
config.ProcessInstruction(@"access.virtAccounts.New.permitTerminalShell no");
config.ProcessInstruction(@"access.virtAccounts.New.permitExecRequests no");
config.ProcessInstruction(@"access.virtAccounts.New.permitSftp yes");
config.ProcessInstruction(@"access.virtAccounts.New.sfsMap.useDefaultSfsMap false");
// Backslashes in rootPath need to be escaped as \\ for ProcessInstruction
// E.g.:
// string rootPath = @"C:\\FTP\\MyFtpFolder";
config.ProcessInstruction(@"access.virtAccounts.New.sfsMap.mountPoints.1.realRootPath """ + rootPath + @"""");
config.ProcessInstruction(@"access.virtAccounts.NewCommit");
config.SaveWinsshdSettings(1);
config.UnlockWinsshdSettings();