|
|
|
@ -21,32 +21,28 @@ func initConfig(c *cli.Context) error { |
|
|
|
return config.G.SetConf(port) |
|
|
|
} |
|
|
|
|
|
|
|
// 接收端 管理上传
|
|
|
|
// 目标接收端,接收发送来的文件
|
|
|
|
func receiveClient() error { |
|
|
|
// 加入udp 监听
|
|
|
|
go discovery.Listen() |
|
|
|
//接收者角色
|
|
|
|
|
|
|
|
// 注释上面的局域网广播
|
|
|
|
fmt.Println("xtfs run as receive role...") |
|
|
|
// 显示状态等
|
|
|
|
// http.HandleFunc("/", handler.ReceiveStatus)
|
|
|
|
http.HandleFunc("/", handler.ReceiveHandler) |
|
|
|
|
|
|
|
fmt.Println("Waiting for receive...") |
|
|
|
// 开启web 服务,
|
|
|
|
return http.ListenAndServe(config.G.WildcardAddress, nil) |
|
|
|
} |
|
|
|
|
|
|
|
// 入口函数
|
|
|
|
/** |
|
|
|
* 保留接收的功能,用来做接收端 |
|
|
|
fs |
|
|
|
**/ |
|
|
|
func main() { |
|
|
|
app := &cli.App{ |
|
|
|
Name: "xtfs", |
|
|
|
Usage: "simple file transfer tool", |
|
|
|
UsageText: "xtfs [global options] [filename|foldername]", |
|
|
|
Description: "xtfs is a simple command-line tool for fast local file/folder sharing", |
|
|
|
Name: "fstc", |
|
|
|
Usage: "fstc --t|--h|--v", |
|
|
|
UsageText: "fstc [global options] [filename|foldername]", |
|
|
|
Description: "fstc is a command-line tool", |
|
|
|
Flags: []cli.Flag{ |
|
|
|
&cli.StringFlag{ |
|
|
|
Name: "port", |
|
|
|
@ -58,19 +54,35 @@ func main() { |
|
|
|
&cli.BoolFlag{ |
|
|
|
Name: "version", |
|
|
|
Aliases: []string{"v"}, |
|
|
|
Usage: "print the version", |
|
|
|
Usage: "v1.02", |
|
|
|
}, |
|
|
|
// 监听的目录位置
|
|
|
|
&cli.StringFlag{ |
|
|
|
Name: "target", |
|
|
|
Aliases: []string{"t"}, |
|
|
|
Usage: "eg:fstc --t /home", |
|
|
|
}, |
|
|
|
}, |
|
|
|
Action: func(c *cli.Context) error { |
|
|
|
// if c.NArg() > 0 {
|
|
|
|
// currentPath := filepath.ToSlash(c.Args().Get(0))
|
|
|
|
// config.G.FilePath = currentPath
|
|
|
|
// return sendClient()
|
|
|
|
// }
|
|
|
|
// 接收输入的 监听目录的位置
|
|
|
|
tgdir := c.String("t") |
|
|
|
if tgdir == "" { |
|
|
|
dir, err := os.Getwd() |
|
|
|
if err == nil { |
|
|
|
tgdir = dir |
|
|
|
} |
|
|
|
//
|
|
|
|
fmt.Printf("work diretctory is:%s\n", tgdir) |
|
|
|
} |
|
|
|
|
|
|
|
// 工作目录
|
|
|
|
config.G.FilePath = tgdir |
|
|
|
return receiveClient() |
|
|
|
|
|
|
|
}, |
|
|
|
Before: initConfig, |
|
|
|
} |
|
|
|
|
|
|
|
err := app.Run(os.Args) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err.Error()) |
|
|
|
|