0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

text works

This commit is contained in:
Zack Scholl 2020-09-02 17:24:32 -07:00
parent ea781e569b
commit 48d63e4854
2 changed files with 44 additions and 0 deletions

View file

@ -50,6 +50,7 @@ func Run() (err error) {
ArgsUsage: "[filename]",
Flags: []cli.Flag{
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-multi", Usage: "disable multiplexing"},
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"),
NoMultiplexing: c.Bool("no-multi"),
RelayPassword: c.GlobalString("pass"),
SendingText: c.String("text") != "",
}
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
crocOptions.RelayAddress6 = ""
@ -196,6 +198,18 @@ func send(c *cli.Context) (err error) {
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 {
fnames = append([]string{c.Args().First()}, c.Args().Tail()...)
}
@ -246,6 +260,26 @@ func getStdin() (fnames []string, err error) {
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) {
haveFolder = false
paths = []string{}

View file

@ -61,6 +61,7 @@ type Options struct {
NoMultiplexing bool
DisableLocal bool
Ask bool
SendingText bool
}
// Client holds the state of the croc transfer
@ -137,6 +138,7 @@ type SenderInfo struct {
FilesToTransfer []FileInfo
MachineID string
Ask bool
SendingText bool
}
// 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].Name,
)
log.Debugf("pathToFile: %s", pathToFile)
// close if not closed already
c.CurrentFile.Close()
if err := os.Remove(pathToFile); err != nil {
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)
return
}
c.Options.SendingText = senderInfo.SendingText
if c.Options.SendingText {
c.Options.Stdout = true
}
c.FilesToTransfer = senderInfo.FilesToTransfer
fname := fmt.Sprintf("%d files", len(c.FilesToTransfer))
if len(c.FilesToTransfer) == 1 {
@ -937,6 +946,7 @@ func (c *Client) updateIfSenderChannelSecured() (err error) {
FilesToTransfer: c.FilesToTransfer,
MachineID: machID,
Ask: c.Options.Ask,
SendingText: c.Options.SendingText,
})
if err != nil {
log.Error(err)