I have some problem to upload an existing file to a ftp using jlaffaye/ftp. There is no “upload” command. The closest I have found is StorFrom()
But the syntax is a hidden secret for me. I cannot find any example how to use this.
package main
import (
"fmt"
"github.com/jlaffaye/ftp"
"io"
"os"
"time"
)
func send2ftp(filename string) {
c, err := ftp.Dial("ftp.test.com:21", ftp.DialWithTimeout(5*time.Second))
if err != nil {
fmt.Println(err)
}
err = c.Login("test", "test")
if err != nil {
fmt.Println(err)
}
if _, err := os.Stat(filename); err != nil {
if os.IsNotExist(err) {
fmt.Println("does not exist")
}
} else {
fmt.Println("exists")
}
err = c.StorFrom(filename, io.Reader, 0)
if err != nil {
panic(err)
}
}
https://play.golang.com/p/xPykHDRei-U
This attempt to find a syntax gives this error:
type io.Reader is not an expression
The question is simple: How do I upload an existing file to ftp? Or how do I create a file at ftp using a string value.