mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Add catfiles
This commit is contained in:
parent
746f1fe193
commit
5eff228a3d
2 changed files with 35 additions and 20 deletions
31
connect.go
31
connect.go
|
@ -290,7 +290,9 @@ func (c *Connection) runClient() error {
|
||||||
if !gotOK {
|
if !gotOK {
|
||||||
return errors.New("Transfer interrupted")
|
return errors.New("Transfer interrupted")
|
||||||
}
|
}
|
||||||
c.catFile(c.File.Name)
|
if err := c.catFile(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
log.Debugf("Code: [%s]", c.Code)
|
log.Debugf("Code: [%s]", c.Code)
|
||||||
if c.DontEncrypt {
|
if c.DontEncrypt {
|
||||||
if err := CopyFile(c.File.Name+".enc", c.File.Name); err != nil {
|
if err := CopyFile(c.File.Name+".enc", c.File.Name); err != nil {
|
||||||
|
@ -330,28 +332,17 @@ func fileAlreadyExists(s []string, f string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connection) catFile(fname string) {
|
func (c *Connection) catFile() error {
|
||||||
// cat the file
|
// cat the file
|
||||||
os.Remove(fname)
|
files := make([]string, c.NumberOfConnections)
|
||||||
finished, err := os.Create(fname + ".enc")
|
for id := range files {
|
||||||
defer finished.Close()
|
files[id] = c.File.Name + "." + strconv.Itoa(id)
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
for id := 0; id < c.NumberOfConnections; id++ {
|
toRemove := true
|
||||||
fh, err := os.Open(fname + "." + strconv.Itoa(id))
|
if c.Debug {
|
||||||
if err != nil {
|
toRemove = false
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
return CatFiles(files, c.File.Name+".enc", toRemove)
|
||||||
_, err = io.Copy(finished, fh)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
fh.Close()
|
|
||||||
os.Remove(fname + "." + strconv.Itoa(id))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connection) receiveFile(id int, connection net.Conn) error {
|
func (c *Connection) receiveFile(id int, connection net.Conn) error {
|
||||||
|
|
24
utils.go
24
utils.go
|
@ -9,6 +9,30 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func CatFiles(files []string, outfile string, remove ...bool) error {
|
||||||
|
finished, err := os.Create(outfile)
|
||||||
|
defer finished.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i := range files {
|
||||||
|
fh, err := os.Open(files[i])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(finished, fh)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fh.Close()
|
||||||
|
if len(remove) > 0 && remove[0] {
|
||||||
|
os.Remove(files[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SplitFile
|
// SplitFile
|
||||||
func SplitFile(fileName string, numPieces int) (err error) {
|
func SplitFile(fileName string, numPieces int) (err error) {
|
||||||
file, err := os.Open(fileName)
|
file, err := os.Open(fileName)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue