2017-08-10 111 views
1

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

+0

也许这有帮助https://forum.filezilla-project.org/viewtopic.php?t=5228 –

+0

你有没有做过任何研究?搜索“c#sftp”会产生大量有用的页面。 – Kenster

+0

@Kenster:我已经做了研究,但没有得到.. – LGB

回答

0

1)为了使bitvise SSH服务器帐户

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

      [email protected] = "Domain_Name"; 
      [email protected] = "Account_Name"; 
      [email protected] = cfg.DefaultYesNo.yes; 
      [email protected](); 
      [email protected]@new.realRootPath = "C:\\Sftp\\User"; 
      [email protected]mit(); 
      cfg.settings.access.winAccountsEx.NewCommit(); 
      cfg.UnlockServerSettings(); 
      cfg.SaveServerSettings(); 


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

2窗户)为使虚拟bitvise SSH服务器帐户

private void AssignPowerSchoolCredentials() 
    { 
     try 
     { 
      var cfg = new CBssCfg726("BssCfg726.BssCfg726"); 
      cfg.SetSite("Bitvise SSH Server");    
      cfg.LoadServerSettings(); 

      [email protected] = "Virtual_Account_name"; 
      [email protected]("Password"); 
      [email protected] = "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); 
       } 
      }     
      [email protected][email protected] = "127.0.0.1"; 
      [email protected][email protected] = 80; 
      [email protected][email protected] = "Default"; 
      [email protected] = cfg.DefaultYesNo.yes; 
      [email protected](); 
      [email protected]@new.sfsMountPath = "/"; 
      [email protected]@new.realRootPath = "Folder_path"; 
      [email protected]mmit(); 
      [email protected].NewCommit(); 
      cfg.settings.access.virtAccountsEx.NewCommit(); 
      cfg.SaveServerSettings(); 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 
    } 
+0

还可以为BssCfg726Lib或BssCfg721Lib等添加反抗,无论您的解决方案如何。 –

+0

这段代码需要以管理员身份运行。 – LGB

0

您可以通过修改配置文件来创建具有C#代码的用户。这意味着您将通过写入文件来创建/删除/更新用户。

可以做这样的事情:

try 
{ 
    string hely = @"C:\Program Files (x86)\FileZilla Server\FileZilla Server.xml"; 
    StreamWriter wr = new StreamWriter(hely, false); 
    wr.WriteLine("<FileZillaServer>"); 
    wr.WriteLine("  <Settings>"); 
    wr.WriteLine("  <Item name=\"Admin port\" type=\"numeric\">14147</Item>"); 
    wr.WriteLine(" </Settings>"); 
    wr.WriteLine(" <Groups />"); 
    wr.WriteLine(" <Users>"); 
    wr.WriteLine(" <User Name=\"test\">"); 
    wr.WriteLine("  <Option Name=\"Pass\">test</Option>"); 
    wr.WriteLine("  <Option Name=\"Group\"></Option>"); 
    wr.WriteLine("  <Option Name=\"Bypass server userlimit\">0</Option>"); 
    wr.WriteLine("  <Option Name=\"User Limit\">0</Option>"); 
    wr.WriteLine("  <Option Name=\"IP Limit\">0</Option>"); 
    wr.WriteLine("  <Option Name=\"Enabled\">1</Option>"); 
    wr.WriteLine("  <Option Name=\"Comments\">test</Option>"); 
    wr.WriteLine("  <Option Name=\"ForceSsl\">0</Option>"); 
    wr.WriteLine(" <IpFilter>"); 
    wr.WriteLine("  <Disallowed />"); 
    wr.WriteLine("  <Allowed />"); 
    wr.WriteLine(" </IpFilter>"); 
    wr.WriteLine(" <Permissions>"); 
    wr.WriteLine("  <Permission Dir=\"D:\\FTP_Root\">"); 
    wr.WriteLine("  <Option Name=\"FileRead\">1</Option>"); 
    wr.WriteLine("  <Option Name=\"FileWrite\">1</Option>"); 
    wr.WriteLine("  <Option Name=\"FileDelete\">1</Option>"); 
    wr.WriteLine("  <Option Name=\"FileAppend\">1</Option>"); 
    wr.WriteLine("  <Option Name=\"DirCreate\">1</Option>"); 
    wr.WriteLine("  <Option Name=\"DirDelete\">1</Option>"); 
    wr.WriteLine("  <Option Name=\"DirList\">0</Option>"); 
    wr.WriteLine("  <Option Name=\"DirSubdirs\">1</Option>"); 
    wr.WriteLine("  <Option Name=\"IsHome\">1</Option>"); 
    wr.WriteLine("  <Option Name=\"AutoCreate\">0</Option>"); 
    wr.WriteLine(" </Permission>"); 
    wr.WriteLine(" </Permissions>"); 
    wr.WriteLine("<SpeedLimits DlType=\"0\" DlLimit=\"10\"  ServerDlLimitBypass=\"0\" UlType=\"0\" UlLimit=\"10\"   ServerUlLimitBypass=\"0\">"); 
    wr.WriteLine("    <Download />"); 
    wr.WriteLine("   <Upload />"); 
    wr.WriteLine("  </SpeedLimits>"); 
    wr.WriteLine(" </User>"); 
    wr.WriteLine(" </Users>"); 
    wr.WriteLine("</FileZillaServer>"); 
    wr.Close(); 
    string pathtofilezilla = @"C:\Program Files (x86)\FileZilla Server"; 
    Process.Start("CMD.exe", "/C \"" + pathtofilezilla + "\\FileZilla Server.exe\" /reload-config"); 
} 
catch (Exception ex) 
{ 
    throw ex; 
} 
+0

你能告诉我代码或任何演示的.. ..? – LGB

+1

我想你从这个链接复制答案https://stackoverflow.com/questions/25967290/creating-sftp-or-ftp-user-account-through-c-sharp-code但它不是有用的bcuz它创建的FTP用户不是SFTP用户 – LGB

相关问题