~kota/pcf

12b4d455cf93b77098819642fb88c8fd47dde53f — Dakota Walsh 2 years ago 0fbb791
initial ftp library implementation

This patch imports a fairly solid go ftp library and implements some
basic connection and testing.
3 files changed, 32 insertions(+), 10 deletions(-)

M go.mod
A go.sum
M main.go
M go.mod => go.mod +2 -0
@@ 1,3 1,5 @@
module git.sr.ht/~kota/pcf

go 1.12

require github.com/jlaffaye/ftp v0.0.0-20190721194432-7cd8b0bcf3fc

A go.sum => go.sum +2 -0
@@ 0,0 1,2 @@
github.com/jlaffaye/ftp v0.0.0-20190721194432-7cd8b0bcf3fc h1:Mc2Gk3kF0Uqx+cI97pN0gbgZb0DVW2L+htrZSKkOmtE=
github.com/jlaffaye/ftp v0.0.0-20190721194432-7cd8b0bcf3fc/go.mod h1:lli8NYPQOFy3O++YmYbqVgOcQ1JPCwdOy+5zSjKJ9qY=

M main.go => main.go +28 -10
@@ 4,25 4,43 @@
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"github.com/jlaffaye/ftp"
	"os"
	"path"
	"time"
)

// var addr = "paste.cf"
// var pub = "incoming"
// var max = 10 * 1024 * 1024
func upload(f *os.File) {
	input := bufio.NewScanner(f)
	for input.Scan() {
		fmt.Println(input.Text())
var addr = "paste.cf:21"
var pub = "incoming"
var max = 10 * 1024 * 1024

// upload files to a connection
func upload() {
	c, err := ftp.Dial(addr, ftp.DialWithTimeout(5*time.Second))
	if err != nil {
		fmt.Fprintf(os.Stderr, "pcf: dial: %v\n", err)
	}
	err = c.Login("anonymous", "anonymous")
	if err != nil {
		fmt.Fprintf(os.Stderr, "pcf: login: %v\n", err)
	}
	data := bytes.NewBufferString("Hello World\n")
	err = c.Stor(path.Join(pub, "test-file.txt"), data)
	if err != nil {
		fmt.Fprintf(os.Stderr, "pcf: put: %v\n", err)
	}
	err = c.Quit()
	if err != nil {
		fmt.Fprintf(os.Stderr, "pcf: quit: %v\n", err)
	}
}

func main() {
	files := os.Args[1:]
	if len(files) == 0 {
		upload(os.Stdin)
		upload()
	} else {
		for _, arg := range files {
			f, err := os.Open(arg)


@@ 30,7 48,7 @@ func main() {
				fmt.Fprintf(os.Stderr, "pcf: %v\n", err)
				continue
			}
			upload(f)
			upload()
			f.Close()
		}
	}