-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFolderOperations.cs
36 lines (33 loc) · 1.22 KB
/
FolderOperations.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Renci.SshNet;
namespace ADSync
{
internal class FolderOperations
{
SshClient client;
string homeFoldersPath;
public FolderOperations(string serverName, string userName, string password, string homeFoldersPath)
{
var connectionInfo = new ConnectionInfo(
serverName, userName, new PasswordAuthenticationMethod(userName, password));
client = new SshClient(connectionInfo);
client.Connect();
client.KeepAliveInterval = new TimeSpan(0, 3, 0);
this.homeFoldersPath = homeFoldersPath;
}
public bool DeleteUserHomeFolder(string logonName)
{
try
{
if(!client.IsConnected) client.Connect();
client.CreateCommand("rm -rf " + homeFoldersPath + logonName).Execute();
Console.WriteLine("Home folder deleted for user " + logonName);
return true;
}
catch (Exception ex)
{
Console.WriteLine("Error while deleting home folder for user " + logonName + " ... " + ex.ToString());
return false;
}
}
}
}