-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenSSHSyncExt.cs
61 lines (50 loc) · 1.18 KB
/
OpenSSHSyncExt.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using KeePass.Plugins;
using System.Net;
using System.Diagnostics;
using KeePassLib.Utility;
namespace OpenSSHSync
{
public sealed class OpenSSHSyncExt : Plugin
{
internal const string SSH = "ssh";
class SftpRequestCreator : IWebRequestCreate
{
public WebRequest Create (Uri uri)
{
return new SftpWebRequest (uri);
}
}
#pragma warning disable 414
private IPluginHost pluginHost;
#pragma warning restore 414
private bool CheckSshCommand ()
{
try {
var process = Process.Start (new ProcessStartInfo {
FileName = SSH,
Arguments = "-V",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
});
#pragma warning disable 219
var version = process.StandardError.ReadLine ();
#pragma warning restore 219
return process.ExitCode != 255;
} catch {
MessageService.ShowWarning ("command '{0}' not found in PATH", SSH);
return false;
}
}
public override bool Initialize (IPluginHost host)
{
this.pluginHost = host;
if (CheckSshCommand ()) {
WebRequest.RegisterPrefix ("sftp", new SftpRequestCreator ());
return true;
}
return false;
}
}
}