diff options
author | Kenneth Hsu <kennethhsu@gmail.com> | 2018-11-22 07:25:41 +0300 |
---|---|---|
committer | Kenneth Hsu <kennethhsu@gmail.com> | 2018-11-22 07:38:36 +0300 |
commit | 609c32feb2c93b316a1850bf502eb839f454f329 (patch) | |
tree | 865d1e48b8e8d887afd977fdea3cd5a47c026952 /Duplicati/Library/Backend | |
parent | e54789d71c461d47c7319b6cef58eb5a119e0374 (diff) |
Create parent directories as needed for SFTP backend.
If the user specifies a path with multiple directories that do not
exist, the SftpClient.CreateDirectory method does not create all the
missing parent directories. As such, we have to do so ourselves.
This addresses issue #2080.
Diffstat (limited to 'Duplicati/Library/Backend')
-rw-r--r-- | Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs b/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs index af0801f53..bc84feb3a 100644 --- a/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs +++ b/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs @@ -115,7 +115,26 @@ namespace Duplicati.Library.Backend public void CreateFolder()
{
CreateConnection();
- m_con.CreateDirectory(m_path);
+
+ // Since the SftpClient.CreateDirectory method does not create all the parent directories
+ // as needed, this has to be done manually.
+ string partialPath = String.Empty;
+ foreach (string part in m_path.Split('/').Where(x => !String.IsNullOrEmpty(x))) + {
+ partialPath += $"/{part}"; + if (m_con.Exists(partialPath)) + { + Renci.SshNet.Sftp.SftpFileAttributes attributes = m_con.GetAttributes(partialPath); + if (!attributes.IsDirectory) + { + throw new ArgumentException($"The path {partialPath} already exists and is not a directory."); + } + }
+ else + { + m_con.CreateDirectory(partialPath); + } + }
}
public string DisplayName
|