-
Notifications
You must be signed in to change notification settings - Fork 0
/
filecopy.go
54 lines (43 loc) · 1.02 KB
/
filecopy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"log"
"net/http"
"strings"
"os"
"io"
)
func filecopy(w http.ResponseWriter, r *http.Request){
r.ParseForm()
if r.Method == "GET" {
//fmt.Fprintf(w, "Error Method")
file := strings.TrimSpace(r.FormValue("file"))
giveSource := strings.TrimSpace(r.FormValue("source"))
giveDest := strings.TrimSpace(r.FormValue("dest"))
fmt.Println("file:", file)
source := giveSource + ":/" + file
dest := "C:/" + giveDest + "/" + file
from, err := os.Open(source)
check(err)
defer from.Close()
to, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE, 0666)
check(err)
defer to.Close()
_, err = io.Copy(to, from)
check(err)
} else {
}
}
func handleRequests() {
http.HandleFunc("/", filecopy)
log.Fatal(http.ListenAndServe(":8181", nil))
}
func main() {
handleRequests()
}
func check(err error) {
if err != nil {
fmt.Println("Error : %s", err.Error())
//os.Exit(1)
}
}