func listFiles(cmd *cobra.Command, args []string) { url := core.UrlHandler(ToadHost, ToadPort, "/listfiles", "") resp, err := http.Get(url) if err != nil { common.IfExit(err) } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) if err != nil { common.IfExit(err) } log.Warn(string(b)) }
func putFiles(cmd *cobra.Command, args []string) { fileName := args[0] file, err := os.Open(fileName) defer file.Close() if err != nil { common.IfExit(err) } url := core.UrlHandler(ToadHost, ToadPort, "/postfile?fileName=", fileName) _, err = http.Post(url, "", file) if err != nil { common.IfExit(err) } log.Warn("success. file added to toadserver") }
func getFiles(cmd *cobra.Command, args []string) { fileName := args[0] url := core.UrlHandler(ToadHost, ToadPort, "/getfile?fileName=", fileName) resp, err := http.Get(url) if err != nil { common.IfExit(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { common.IfExit(err) } if err := ioutil.WriteFile(fileName, body, 0777); err != nil { common.IfExit(err) } }