2017-08-10 110 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

相關問題