1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-23 23:54:17 +03:00

add stdin

This commit is contained in:
Zack Scholl 2018-07-01 14:53:35 -07:00
parent ebad469554
commit f315a0bb79
3 changed files with 11 additions and 3 deletions

11
main.go
View File

@ -103,12 +103,19 @@ func main() {
} }
func send(c *cli.Context) error { func send(c *cli.Context) error {
if c.Args().First() == "" { stat, _ := os.Stdin.Stat()
var fname string
if (stat.Mode() & os.ModeCharDevice) == 0 {
fname = "stdin"
} else {
fname = c.Args().First()
}
if fname == "" {
return errors.New("must specify file: croc send [filename]") return errors.New("must specify file: croc send [filename]")
} }
cr.UseCompression = c.BoolT("compress") cr.UseCompression = c.BoolT("compress")
cr.UseEncryption = c.BoolT("encrypt") cr.UseEncryption = c.BoolT("encrypt")
return cr.Send(c.Args().First(), c.GlobalString("code")) return cr.Send(fname, c.GlobalString("code"))
} }
func receive(c *cli.Context) error { func receive(c *cli.Context) error {

View File

@ -84,6 +84,7 @@ func (c *Croc) Send(fname string, codePhrase string) (err error) {
d.TcpPorts = []string{"27140", "27141"} d.TcpPorts = []string{"27140", "27141"}
go d.startRelay() go d.startRelay()
go d.startServer() go d.startServer()
time.Sleep(100 * time.Millisecond)
ce := Init() ce := Init()
ce.WebsocketAddress = "ws://127.0.0.1:8140" ce.WebsocketAddress = "ws://127.0.0.1:8140"
// copy over the information // copy over the information

View File

@ -41,7 +41,7 @@ func (c *Croc) processFile(src string) (err error) {
return return
} }
// fd.Name is what the user will see // fd.Name is what the user will see
fd.Name = "stdin" fd.Name = filename
fd.DeleteAfterSending = true fd.DeleteAfterSending = true
} else { } else {
if !exists(src) { if !exists(src) {