func listDir(c *easyftp.Client) { r, err := c.List(".") if err != nil { fmt.Println("LIST: ", err) return } defer r.Close() io.Copy(os.Stdout, r) }
func uploadFile(c *easyftp.Client, from string, to string) { r, err := os.Open(from) if err != nil { fmt.Println("failed to open upload local file:", err) return } defer r.Close() err = c.Stor(to, r) if err != nil { fmt.Println("failed to open remote file:", err) return } }
func downloadFile(c *easyftp.Client, from string, to string) { w, err := os.Create(to) if err != nil { fmt.Println("failed to open download dest file:", err) return } defer w.Close() r, err := c.Retr(from) if err != nil { fmt.Println("failed to open remote file:", err) return } defer r.Close() io.Copy(w, r) }
func abortedDownloadFile(c *easyftp.Client, from string, to string) { w, err := os.Create(to) if err != nil { fmt.Println("failed to open download dest file:", err) return } defer w.Close() r, err := c.Retr(from) if err != nil { fmt.Println("failed to open remote file:", err) return } err = r.Close() if err != nil { fmt.Println("aborted file downloading:", err) return } // We close the connection without reading anything // io.Copy(w, r) }