diff --git a/pkg/ssh/sshclient.go b/pkg/ssh/sshclient.go index 5d819b2d..feaabe32 100644 --- a/pkg/ssh/sshclient.go +++ b/pkg/ssh/sshclient.go @@ -11,6 +11,7 @@ import ( "io" "io/ioutil" "os" + "path/filepath" "github.com/pkg/sftp" "go.uber.org/zap" @@ -145,6 +146,13 @@ func (c *client) UploadFile(localFile string, remoteFilePath string, mode os.Fil // create a progrssReader that will call the callback function after each read progressReader := newProgressCBReader(fInfo.Size(), localFileReader, cb) + dir, _ := filepath.Split(remoteFilePath) + if dir != "" { + if err := c.sftpClient.MkdirAll(dir); err != nil { + return fmt.Errorf("Could not create remote dir %s: %s", dir, err) + } + } + remoteFile, err := c.sftpClient.Create(remoteFilePath) if err != nil { return fmt.Errorf("unable to create file: %s", err)