Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs')
-rw-r--r--Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs42
1 files changed, 30 insertions, 12 deletions
diff --git a/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs b/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs
index a2a44e249..1131c521f 100644
--- a/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs
+++ b/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs
@@ -34,6 +34,8 @@ namespace Duplicati.Library.Backend
public const string SSH_FINGERPRINT_OPTION = "ssh-fingerprint";
public const string SSH_FINGERPRINT_ACCEPT_ANY_OPTION = "ssh-accept-any-fingerprints";
public const string KEYFILE_URI = "sshkey://";
+ public const string SSH_TIMEOUT_OPTION = "ssh-operation-timeout";
+ public const string SSH_KEEPALIVE_OPTION = "ssh-keepalive";
Dictionary<string, string> m_options;
@@ -43,6 +45,8 @@ namespace Duplicati.Library.Backend
private string m_password;
private string m_fingerprint;
private bool m_fingerprintallowall;
+ private TimeSpan m_operationtimeout;
+ private TimeSpan m_keepaliveinterval;
private int m_port = 22;
@@ -69,8 +73,6 @@ namespace Duplicati.Library.Backend
m_username = uri.Username;
if (!string.IsNullOrEmpty(uri.Password))
m_password = uri.Password;
- if (uri.QueryParameters != null && uri.QueryParameters[SSH_FINGERPRINT_OPTION] != null)
- m_fingerprint = uri.QueryParameters[SSH_FINGERPRINT_OPTION];
m_fingerprintallowall = Utility.Utility.ParseBoolOption(options, SSH_FINGERPRINT_ACCEPT_ANY_OPTION);
@@ -86,13 +88,25 @@ namespace Duplicati.Library.Backend
if (uri.Port > 0)
m_port = uri.Port;
+
+ string timeoutstr;
+ options.TryGetValue(SSH_TIMEOUT_OPTION, out timeoutstr);
+
+ if (!string.IsNullOrWhiteSpace(timeoutstr))
+ m_operationtimeout = Library.Utility.Timeparser.ParseTimeSpan(timeoutstr);
+
+ options.TryGetValue(SSH_KEEPALIVE_OPTION, out timeoutstr);
+
+ if (!string.IsNullOrWhiteSpace(timeoutstr))
+ m_keepaliveinterval = Library.Utility.Timeparser.ParseTimeSpan(timeoutstr);
+
}
#region IBackend Members
public void Test()
{
- List();
+ this.TestList();
}
public void CreateFolder()
@@ -150,8 +164,11 @@ namespace Duplicati.Library.Backend
new CommandLineArgument("auth-password", CommandLineArgument.ArgumentType.Password, Strings.SSHv2Backend.DescriptionAuthPasswordShort, Strings.SSHv2Backend.DescriptionAuthPasswordLong),
new CommandLineArgument("auth-username", CommandLineArgument.ArgumentType.String, Strings.SSHv2Backend.DescriptionAuthUsernameShort, Strings.SSHv2Backend.DescriptionAuthUsernameLong),
new CommandLineArgument(SSH_FINGERPRINT_OPTION, CommandLineArgument.ArgumentType.String, Strings.SSHv2Backend.DescriptionFingerprintShort, Strings.SSHv2Backend.DescriptionFingerprintLong),
+ new CommandLineArgument(SSH_FINGERPRINT_ACCEPT_ANY_OPTION, CommandLineArgument.ArgumentType.Boolean, Strings.SSHv2Backend.DescriptionAnyFingerprintShort, Strings.SSHv2Backend.DescriptionAnyFingerprintLong),
new CommandLineArgument(SSH_KEYFILE_OPTION, CommandLineArgument.ArgumentType.Path, Strings.SSHv2Backend.DescriptionSshkeyfileShort, Strings.SSHv2Backend.DescriptionSshkeyfileLong),
new CommandLineArgument(SSH_KEYFILE_INLINE, CommandLineArgument.ArgumentType.Password, Strings.SSHv2Backend.DescriptionSshkeyShort, Strings.SSHv2Backend.DescriptionSshkeyLong(KEYFILE_URI)),
+ new CommandLineArgument(SSH_TIMEOUT_OPTION, CommandLineArgument.ArgumentType.Timespan, Strings.SSHv2Backend.DescriptionSshtimeoutShort, Strings.SSHv2Backend.DescriptionSshtimeoutLong, "0"),
+ new CommandLineArgument(SSH_KEEPALIVE_OPTION, CommandLineArgument.ArgumentType.Timespan, Strings.SSHv2Backend.DescriptionSshkeepaliveShort, Strings.SSHv2Backend.DescriptionSshkeepaliveLong, "0"),
});
}
@@ -240,7 +257,7 @@ namespace Duplicati.Library.Backend
if (!string.IsNullOrWhiteSpace(keyfile))
con = new SftpClient(m_server, m_port, m_username, ValidateKeyFile(keyfile, m_password));
else
- con = new SftpClient(m_server, m_port, m_username, m_password);
+ con = new SftpClient(m_server, m_port, m_username, m_password ?? string.Empty);
con.HostKeyReceived += delegate (object sender, HostKeyEventArgs e)
{
@@ -263,6 +280,11 @@ namespace Duplicati.Library.Backend
e.CanTrust = true;
};
+ if (m_operationtimeout.Ticks != 0)
+ con.OperationTimeout = m_operationtimeout;
+ if (m_keepaliveinterval.Ticks != 0)
+ con.KeepAliveInterval = m_keepaliveinterval;
+
con.Connect();
m_con = con;
@@ -291,10 +313,8 @@ namespace Duplicati.Library.Backend
}
}
- public List<IFileEntry> List()
+ public IEnumerable<IFileEntry> List()
{
- var files = new List<IFileEntry>();
-
string path = ".";
CreateConnection();
@@ -302,14 +322,12 @@ namespace Duplicati.Library.Backend
foreach (Renci.SshNet.Sftp.SftpFile ls in m_con.ListDirectory(path))
if (ls.Name.ToString() != "." && ls.Name.ToString() != "..")
- files.Add(new FileEntry(ls.Name.ToString(), ls.Length, ls.LastAccessTime, ls.LastWriteTime) { IsFolder = ls.Attributes.IsDirectory });
-
- return files;
+ yield return new FileEntry(ls.Name.ToString(), ls.Length, ls.LastAccessTime, ls.LastWriteTime) { IsFolder = ls.Attributes.IsDirectory };
}
public static Renci.SshNet.PrivateKeyFile ValidateKeyFile(string filename, string password)
{
- if (filename.StartsWith(KEYFILE_URI, StringComparison.InvariantCultureIgnoreCase))
+ if (filename.StartsWith(KEYFILE_URI, StringComparison.OrdinalIgnoreCase))
{
using (var ms = new System.IO.MemoryStream())
using (var sr = new System.IO.StreamWriter(ms))
@@ -344,4 +362,4 @@ namespace Duplicati.Library.Backend
}
}
}
-}
+}