mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
text works
This commit is contained in:
parent
ea781e569b
commit
48d63e4854
2 changed files with 44 additions and 0 deletions
|
@ -50,6 +50,7 @@ func Run() (err error) {
|
||||||
ArgsUsage: "[filename]",
|
ArgsUsage: "[filename]",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{Name: "code, c", Usage: "codephrase used to connect to relay"},
|
cli.StringFlag{Name: "code, c", Usage: "codephrase used to connect to relay"},
|
||||||
|
cli.StringFlag{Name: "text, t", Usage: "send some text"},
|
||||||
cli.BoolFlag{Name: "no-local", Usage: "disable local relay when sending"},
|
cli.BoolFlag{Name: "no-local", Usage: "disable local relay when sending"},
|
||||||
cli.BoolFlag{Name: "no-multi", Usage: "disable multiplexing"},
|
cli.BoolFlag{Name: "no-multi", Usage: "disable multiplexing"},
|
||||||
cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the local relay (optional)"},
|
cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the local relay (optional)"},
|
||||||
|
@ -151,6 +152,7 @@ func send(c *cli.Context) (err error) {
|
||||||
Ask: c.GlobalBool("ask"),
|
Ask: c.GlobalBool("ask"),
|
||||||
NoMultiplexing: c.Bool("no-multi"),
|
NoMultiplexing: c.Bool("no-multi"),
|
||||||
RelayPassword: c.GlobalString("pass"),
|
RelayPassword: c.GlobalString("pass"),
|
||||||
|
SendingText: c.String("text") != "",
|
||||||
}
|
}
|
||||||
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
||||||
crocOptions.RelayAddress6 = ""
|
crocOptions.RelayAddress6 = ""
|
||||||
|
@ -196,6 +198,18 @@ func send(c *cli.Context) (err error) {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
} else if c.String("text") != "" {
|
||||||
|
fnames, err = makeTempFileWithString(c.String("text"))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
err = os.Remove(fnames[0])
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fnames = append([]string{c.Args().First()}, c.Args().Tail()...)
|
fnames = append([]string{c.Args().First()}, c.Args().Tail()...)
|
||||||
}
|
}
|
||||||
|
@ -246,6 +260,26 @@ func getStdin() (fnames []string, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeTempFileWithString(s string) (fnames []string, err error) {
|
||||||
|
f, err := ioutil.TempFile(".", "croc-stdin-")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = f.WriteString(s)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fnames = []string{f.Name()}
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func getPaths(fnames []string) (paths []string, haveFolder bool, err error) {
|
func getPaths(fnames []string) (paths []string, haveFolder bool, err error) {
|
||||||
haveFolder = false
|
haveFolder = false
|
||||||
paths = []string{}
|
paths = []string{}
|
||||||
|
|
|
@ -61,6 +61,7 @@ type Options struct {
|
||||||
NoMultiplexing bool
|
NoMultiplexing bool
|
||||||
DisableLocal bool
|
DisableLocal bool
|
||||||
Ask bool
|
Ask bool
|
||||||
|
SendingText bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client holds the state of the croc transfer
|
// Client holds the state of the croc transfer
|
||||||
|
@ -137,6 +138,7 @@ type SenderInfo struct {
|
||||||
FilesToTransfer []FileInfo
|
FilesToTransfer []FileInfo
|
||||||
MachineID string
|
MachineID string
|
||||||
Ask bool
|
Ask bool
|
||||||
|
SendingText bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// New establishes a new connection for transferring files between two instances.
|
// New establishes a new connection for transferring files between two instances.
|
||||||
|
@ -667,6 +669,9 @@ func (c *Client) transfer(options TransferOptions) (err error) {
|
||||||
c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote,
|
c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote,
|
||||||
c.FilesToTransfer[c.FilesToTransferCurrentNum].Name,
|
c.FilesToTransfer[c.FilesToTransferCurrentNum].Name,
|
||||||
)
|
)
|
||||||
|
log.Debugf("pathToFile: %s", pathToFile)
|
||||||
|
// close if not closed already
|
||||||
|
c.CurrentFile.Close()
|
||||||
if err := os.Remove(pathToFile); err != nil {
|
if err := os.Remove(pathToFile); err != nil {
|
||||||
log.Warnf("error removing %s: %v", pathToFile, err)
|
log.Warnf("error removing %s: %v", pathToFile, err)
|
||||||
}
|
}
|
||||||
|
@ -681,6 +686,10 @@ func (c *Client) processMessageFileInfo(m message.Message) (done bool, err error
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
c.Options.SendingText = senderInfo.SendingText
|
||||||
|
if c.Options.SendingText {
|
||||||
|
c.Options.Stdout = true
|
||||||
|
}
|
||||||
c.FilesToTransfer = senderInfo.FilesToTransfer
|
c.FilesToTransfer = senderInfo.FilesToTransfer
|
||||||
fname := fmt.Sprintf("%d files", len(c.FilesToTransfer))
|
fname := fmt.Sprintf("%d files", len(c.FilesToTransfer))
|
||||||
if len(c.FilesToTransfer) == 1 {
|
if len(c.FilesToTransfer) == 1 {
|
||||||
|
@ -937,6 +946,7 @@ func (c *Client) updateIfSenderChannelSecured() (err error) {
|
||||||
FilesToTransfer: c.FilesToTransfer,
|
FilesToTransfer: c.FilesToTransfer,
|
||||||
MachineID: machID,
|
MachineID: machID,
|
||||||
Ask: c.Options.Ask,
|
Ask: c.Options.Ask,
|
||||||
|
SendingText: c.Options.SendingText,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue