mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
commit
ba2c46c1cb
4 changed files with 51 additions and 3 deletions
2
go.mod
2
go.mod
|
@ -15,7 +15,7 @@ require (
|
||||||
github.com/schollz/mnemonicode v1.0.1
|
github.com/schollz/mnemonicode v1.0.1
|
||||||
github.com/schollz/pake/v2 v2.0.4
|
github.com/schollz/pake/v2 v2.0.4
|
||||||
github.com/schollz/peerdiscovery v1.5.2
|
github.com/schollz/peerdiscovery v1.5.2
|
||||||
github.com/schollz/progressbar/v3 v3.4.0
|
github.com/schollz/progressbar/v3 v3.5.0
|
||||||
github.com/schollz/spinner v0.0.0-20180925172146-6bbc5f7804f9
|
github.com/schollz/spinner v0.0.0-20180925172146-6bbc5f7804f9
|
||||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -47,8 +47,8 @@ github.com/schollz/peerdiscovery v1.5.2 h1:gc1iXQ0A9xj58nm7QHs5a1tCoYv7QDIrZbQfZ
|
||||||
github.com/schollz/peerdiscovery v1.5.2/go.mod h1:hSU7N/NkfNH6AZwU/WBcDZtMABVbTfAWk/XD3XKxN+s=
|
github.com/schollz/peerdiscovery v1.5.2/go.mod h1:hSU7N/NkfNH6AZwU/WBcDZtMABVbTfAWk/XD3XKxN+s=
|
||||||
github.com/schollz/progressbar/v2 v2.15.0 h1:dVzHQ8fHRmtPjD3K10jT3Qgn/+H+92jhPrhmxIJfDz8=
|
github.com/schollz/progressbar/v2 v2.15.0 h1:dVzHQ8fHRmtPjD3K10jT3Qgn/+H+92jhPrhmxIJfDz8=
|
||||||
github.com/schollz/progressbar/v2 v2.15.0/go.mod h1:UdPq3prGkfQ7MOzZKlDRpYKcFqEMczbD7YmbPgpzKMI=
|
github.com/schollz/progressbar/v2 v2.15.0/go.mod h1:UdPq3prGkfQ7MOzZKlDRpYKcFqEMczbD7YmbPgpzKMI=
|
||||||
github.com/schollz/progressbar/v3 v3.4.0 h1:jHd2FiF+zpPc7di1m9cHRgt8AaUvId3L5p4bF9Nux9g=
|
github.com/schollz/progressbar/v3 v3.5.0 h1:rVya3NTks1kFmuFKaLYWt/3TYDiE+Cxb1iXuxeEjf5c=
|
||||||
github.com/schollz/progressbar/v3 v3.4.0/go.mod h1:Rp5lZwpgtYmlvmGo1FyDwXMqagyRBQYSDwzlP9QDu84=
|
github.com/schollz/progressbar/v3 v3.5.0/go.mod h1:Rp5lZwpgtYmlvmGo1FyDwXMqagyRBQYSDwzlP9QDu84=
|
||||||
github.com/schollz/spinner v0.0.0-20180925172146-6bbc5f7804f9 h1:y08o5oQ/slxXE/F0uh5dd8mdVvb+w4NLcNSDSq4c2F0=
|
github.com/schollz/spinner v0.0.0-20180925172146-6bbc5f7804f9 h1:y08o5oQ/slxXE/F0uh5dd8mdVvb+w4NLcNSDSq4c2F0=
|
||||||
github.com/schollz/spinner v0.0.0-20180925172146-6bbc5f7804f9/go.mod h1:kCMoQsqzx4MzGJWaALr6tKyCnlrY0kILGLkA1FOiLF4=
|
github.com/schollz/spinner v0.0.0-20180925172146-6bbc5f7804f9/go.mod h1:kCMoQsqzx4MzGJWaALr6tKyCnlrY0kILGLkA1FOiLF4=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||||
|
|
|
@ -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,9 +669,13 @@ 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)
|
||||||
}
|
}
|
||||||
|
fmt.Print("\n")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -681,6 +687,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 +947,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)
|
||||||
|
@ -1087,6 +1098,7 @@ func (c *Client) createEmptyFileAndFinish(fileInfo FileInfo, i int) (err error)
|
||||||
progressbar.OptionShowBytes(true),
|
progressbar.OptionShowBytes(true),
|
||||||
progressbar.OptionShowCount(),
|
progressbar.OptionShowCount(),
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
|
progressbar.OptionSetVisibility(!c.Options.SendingText),
|
||||||
)
|
)
|
||||||
c.bar.Finish()
|
c.bar.Finish()
|
||||||
return
|
return
|
||||||
|
@ -1172,6 +1184,7 @@ func (c *Client) updateState() (err error) {
|
||||||
progressbar.OptionShowBytes(true),
|
progressbar.OptionShowBytes(true),
|
||||||
progressbar.OptionShowCount(),
|
progressbar.OptionShowCount(),
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
|
progressbar.OptionSetVisibility(!c.Options.SendingText),
|
||||||
)
|
)
|
||||||
c.bar.Finish()
|
c.bar.Finish()
|
||||||
}
|
}
|
||||||
|
@ -1217,6 +1230,7 @@ func (c *Client) setBar() {
|
||||||
progressbar.OptionShowCount(),
|
progressbar.OptionShowCount(),
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
progressbar.OptionThrottle(100*time.Millisecond),
|
progressbar.OptionThrottle(100*time.Millisecond),
|
||||||
|
progressbar.OptionSetVisibility(!c.Options.SendingText),
|
||||||
)
|
)
|
||||||
byteToDo := int64(len(c.CurrentFileChunks) * models.TCP_BUFFER_SIZE / 2)
|
byteToDo := int64(len(c.CurrentFileChunks) * models.TCP_BUFFER_SIZE / 2)
|
||||||
if byteToDo > 0 {
|
if byteToDo > 0 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue