通過c#代碼創建SFTP(非FTP)用戶帳戶。 這可能通過我的代碼創建sftp用戶嗎?我使用bitvise SSH服務器作爲我的sftp服務器,filezilla服務器作爲我的ftp服務器,現在我想爲不同的員工創建不同的用戶,以便他們都可以訪問我服務器上的不同文件夾,並且無法訪問訪問彼此的路徑(文件夾)。任何人都可以通過c#代碼對sftp中的用戶創建有一些想法?是否可以使用c#創建SFTP(非FTP)用戶?如果是那麼如何?
1
A
回答
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;
}
相關問題
- 1. 是否可以使用ftp.MakeDirectory在FTP中創建子目錄?
- 2. 通過c#代碼創建SFTP或FTP用戶帳戶
- 3. 是否可以創建一個使用C#或C++代碼的Firefox插件?如果是這樣,怎麼樣?
- 4. 如果我不使用異常,如何檢查映射是否可以創建?
- 5. 是否可以使用Java創建dll?
- 6. 是否可以使用緩存清除共享首選項?如果是,那麼如何清除它?
- 7. 是否可以使用RestSharp創建Firebase用戶?
- 8. 以編程方式使用c#創建SFTP用戶
- 9. 是否可以在Renci SSH.NET上正常工作(不是SFTP)FTP? - 要使用哪個客戶端?
- 10. 您是否可以在用戶控件中創建事件,如果是這樣,如何?
- 11. 是否可以通過FTP代理使用C#FtpWebRequest?
- 12. 是否可以使用C#在FTP中壓縮文件夾?
- 13. 是否可以在Visual Studio 2013中安裝v140構建工具?如果是,那麼如何?
- 14. 是否可以使用JavaScript創建客戶端唯一混搭?
- 15. 是否可以使用JavaScript/AJAX在客戶端創建文件?
- 16. 是否可以使用PHP將文件從FTP上傳到FTP
- 17. 是否可以使用FTP命令重命名FTP文件夾?
- 18. 是否可以從xml創建C#類?
- 19. VisualVM可以用於剖析Maven項目嗎?如果是,那麼如何?
- 20. 是否可以閱讀Windows Phone 7上的用戶文件?如果是,如何?
- 21. 如果沒有本地app.config,是否可以使用System.Configuration?如果可能,如何?
- 22. 是否可以使用C#和JavaScript創建SOAP API
- 23. 那麼,是否可以在layoutSubviews使用自動佈局
- 24. 如何使用jQuery來判斷用戶是否可以滾動?
- 25. 您是否可以擁有使用SFTP服務器的虛擬用戶?
- 26. 是否可以使用apache shiro限制複製粘貼到頁面?如果是,那我該如何實現呢?
- 27. 使用Rails創建FTP用戶帳戶
- 28. 客戶端是否可以決定是否創建HttpContext?
- 29. 如果通過創建包可以完成同樣的事情,那麼繼承的用途是什麼?
- 30. Rails,如何確定用戶是否是今天創建的?
也許這有幫助https://forum.filezilla-project.org/viewtopic.php?t=5228 –
你有沒有做過任何研究?搜索「c#sftp」會產生大量有用的頁面。 – Kenster
@Kenster:我已經做了研究,但沒有得到.. – LGB