From 982f76b4df899757245e736200b21b81bd8f9708 Mon Sep 17 00:00:00 2001 From: nielash <31582349+nielash@users.noreply.github.com> Date: Sat, 29 Jul 2023 22:12:07 -0400 Subject: [PATCH] sftp: support dynamic --sftp-path-override Before this change, rclone always expected --sftp-path-override to be the absolute SSH path to remote:path/subpath which effectively made it unusable for wrapped remotes (for example, when used with a crypt remote, the user would need to provide the full decrypted path.) After this change, the old behavior remains the default, but dynamic paths are now also supported, if the user adds '@' as the first character of --sftp-path-override. Rclone will ignore the '@' and treat the rest of the string as the path to the SFTP remote's root. Rclone will then add any relative subpaths automatically (including unwrapping/decrypting remotes as necessary). In other words, the path_override config parameter can now be used to specify the difference between the SSH and SFTP paths. Once specified in the config, it is no longer necessary to re-specify for each command. See: https://forum.rclone.org/t/sftp-path-override-breaks-on-wrapped-remotes/40025 --- backend/sftp/sftp.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go index 13b30c539..5feb863d6 100644 --- a/backend/sftp/sftp.go +++ b/backend/sftp/sftp.go @@ -168,7 +168,19 @@ E.g. if shared folders can be found in directories representing volumes: E.g. if home directory can be found in a shared folder called "home": - rclone sync /home/local/directory remote:/home/directory --sftp-path-override /volume1/homes/USER/directory`, + rclone sync /home/local/directory remote:/home/directory --sftp-path-override /volume1/homes/USER/directory + +To specify only the path to the SFTP remote's root, and allow rclone to add any relative subpaths automatically (including unwrapping/decrypting remotes as necessary), add the '@' character to the beginning of the path. + +E.g. the first example above could be rewritten as: + + rclone sync /home/local/directory remote:/directory --sftp-path-override @/volume2 + +Note that when using this method with Synology "home" folders, the full "/homes/USER" path should be specified instead of "/home". + +E.g. the second example above should be rewritten as: + + rclone sync /home/local/directory remote:/homes/USER/directory --sftp-path-override @/volume1`, Advanced: true, }, { Name: "set_modtime", @@ -1763,6 +1775,9 @@ func (f *Fs) remotePath(remote string) string { func (f *Fs) remoteShellPath(remote string) string { if f.opt.PathOverride != "" { shellPath := path.Join(f.opt.PathOverride, remote) + if f.opt.PathOverride[0] == '@' { + shellPath = path.Join(strings.TrimPrefix(f.opt.PathOverride, "@"), f.absRoot, remote) + } fs.Debugf(f, "Shell path redirected to %q with option path_override", shellPath) return shellPath }