From 38468ccfb9c5913be055a1e41c8c313c990796c0 Mon Sep 17 00:00:00 2001 From: Jocelyn Le Sage Date: Thu, 19 Oct 2023 12:13:21 -0400 Subject: [PATCH] When uploading/downloading, make sure to truncate the remote/local file when opened. --- sshclient.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sshclient.go b/sshclient.go index f232d8a..5968bfe 100644 --- a/sshclient.go +++ b/sshclient.go @@ -765,7 +765,7 @@ func (rfs *RemoteFileSystem) Upload(hostPath, remotePath string) (retErr error) } defer multierr.AppendErrFunc(hostFile.Close) - remoteFile, err := rfs.sftp.OpenFile(remotePath, os.O_CREATE|os.O_WRONLY) + remoteFile, err := rfs.sftp.OpenFile(remotePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC) if err != nil { return multierr.Append(err) } @@ -791,7 +791,7 @@ func (rfs *RemoteFileSystem) Download(remotePath, hostPath string) (retErr error } defer multierr.AppendErrFunc(remoteFile.Close) - hostFile, err := os.OpenFile(hostPath, os.O_CREATE|os.O_WRONLY, os.ModeAppend|os.ModePerm) + hostFile, err := os.OpenFile(hostPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModeAppend|os.ModePerm) if err != nil { return multierr.Append(err) }