From 57f1bb7bb25bd8541f467ed9507157d90f6ac02b Mon Sep 17 00:00:00 2001 From: Jon Fautley Date: Thu, 4 Jan 2018 14:52:47 +0000 Subject: [PATCH] sftp: add 'set_modtime' hidden configuration option --- docs/content/sftp.md | 5 +++++ sftp/sftp.go | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/content/sftp.md b/docs/content/sftp.md index 3c984744c..6dab5afb5 100644 --- a/docs/content/sftp.md +++ b/docs/content/sftp.md @@ -147,6 +147,11 @@ Modified times are stored on the server to 1 second precision. Modified times are used in syncing and are fully supported. +Some SFTP servers disable setting/modifying the file modification time after +upload (for example, certain configurations of ProFTPd with mod_sftp). If you +are using one of these servers, you can set the option `set_modtime = false` in +your RClone backend configuration to disable this behaviour. + ### Limitations ### SFTP supports checksums if the same login has shell access and `md5sum` diff --git a/sftp/sftp.go b/sftp/sftp.go index 7d287c880..dffc35a91 100644 --- a/sftp/sftp.go +++ b/sftp/sftp.go @@ -812,14 +812,16 @@ func (o *Object) SetModTime(modTime time.Time) error { if err != nil { return errors.Wrap(err, "SetModTime") } - err = c.sftpClient.Chtimes(o.path(), modTime, modTime) - o.fs.putSftpConnection(&c, err) - if err != nil { - return errors.Wrap(err, "SetModTime failed") + if fs.ConfigFileGetBool(o.fs.name, "set_modtime", true) { + err = c.sftpClient.Chtimes(o.path(), modTime, modTime) + o.fs.putSftpConnection(&c, err) + if err != nil { + return errors.Wrap(err, "SetModTime failed") + } } err = o.stat() if err != nil { - return errors.Wrap(err, "SetModTime failed") + return errors.Wrap(err, "SetModTime stat failed") } return nil }