Golang中client.Create("test.txt")报错SSH_FX_OP_UNSUPPORTED的解决方法
Golang中client.Create(“test.txt”)报错SSH_FX_OP_UNSUPPORTED的解决方法 我正在尝试将文件发送到SFTP服务器。我的理解是,我首先需要建立连接,然后创建一个“客户端”。对吗?
但是当我尝试执行 client.Create(filename) 时,出现了以下错误:
sftp: “FeatureNotSupported: This feature is not supported.” (SSH_FX_OP_UNSUPPORTED)
有人知道是什么原因导致这个错误吗?
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)
}
}
更多关于Golang中client.Create("test.txt")报错SSH_FX_OP_UNSUPPORTED的解决方法的实战教程也可以访问 https://www.itying.com/category-94-b0.html
2 回复
有什么线索知道是什么导致了这个问题吗?
经过数小时的研究,我找到了解决这个问题的办法(替换 client.Create):
// 创建目标文件
dstFile, err := client.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC)
//dstFile, err := client.Create(filename)
if err != nil {
fmt.Println(err)
}
更多关于Golang中client.Create("test.txt")报错SSH_FX_OP_UNSUPPORTED的解决方法的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html


