Hi all:
I tried to upload file via SFTP,but the file size is zero when it is
done.Any suggestions? Thanks so much.
//sftp upload
package main
import (
"fmt"
"os"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
)
func main() {
c := &ssh.ClientConfig{
User: "root",
Auth: []ssh.AuthMethod{
ssh.Password("74634265"),
},
}
connection, err := ssh.Dial("tcp", "192.168.44.129:22", c) // replace this
if err != nil {
fmt.Println(err)
return
}
server, err := sftp.NewClient(connection)
if err != nil {
fmt.Println(err)
return
}
// Open the source file
srcFile, err := os.Open("F:/NCA/20161027-1.csv")
if err != nil {
fmt.Println(err)
}
defer srcFile.Close()
// Create the destination file
dstFile, err := server.Create("/root/20161027-1.csv")
if err != nil {
fmt.Println(err)
}
defer dstFile.Close()
// Copy the file
dstFile.WriteTo(srcFile)
}
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.