I am trying to send a file to an sftp. My assumption is that I first have to connect and then create a “client”. Correct?
But when I try to client.Create(filename)
I get this error:
sftp: “FeatureNotSupported: This feature is not supported.” (SSH_FX_OP_UNSUPPORTED)
Any clue what causes this error?
package main
import (
"fmt"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
"io"
"os"
"strings"
)
func main() {
send2ftp("./test.txt")
}
func send2ftp(filename string) {
config := &ssh.ClientConfig{
User: "username",
Auth: []ssh.AuthMethod{
ssh.Password("a_long_password"),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
conn, err := ssh.Dial("tcp", "sftp.test.com:22", config)
if err != nil {
if strings.Contains(err.Error(), "connection refused") {
fmt.Println("SSH isn't up yet")
} else {
fmt.Println(err.Error())
}
}
defer conn.Close()
// create new SFTP client
client, err := sftp.NewClient(conn)
if err != nil {
fmt.Println(err)
}
defer client.Close()
// create destination file
dstFile, err := client.Create(filename)
if err != nil {
fmt.Println(err)
}
defer dstFile.Close()
// create source file
srcFile, err := os.Open(filename)
if err != nil {
fmt.Println(err)
}
// copy source file to destination file
io.Copy(dstFile, srcFile)
if err != nil {
fmt.Println(err)
}
}