hnakamur / go-scp

[Unmaintained] A scp client library written in Go
MIT License
41 stars 23 forks source link

replace '\' to '/' on Windows #6

Closed yamamoto-febc closed 7 years ago

yamamoto-febc commented 7 years ago

This PR will fix to path separator problems when used on Windows.

If you run like following on Windows, it will create a file \remote\path on remote.
But what you need is a directory /remote/path.


scpClient := scp.NewSCP(conn)
scpClient.SendDir("local", "/remote/path", nil) // file `\remote\path` will be created(not a directory) 

The cause is using filepath.Clean as following:

https://github.com/hnakamur/go-scp/blob/master/source.go#L74

func (s *SCP) SendDir(srcDir, destDir string, acceptFn AcceptFunc) error {
    srcDir = filepath.Clean(srcDir)
    destDir = filepath.Clean(destDir)

On Windows , filepath.Clean("/remote/path") return \remote\path. (This value will be used later for starting SCP connection, ex: scp -rtp '\remote\path')

so, when running on Windows, you should replace \ to / on remote path.

hnakamur commented 7 years ago

Thanks for your pull request!