2017-04-15 17:08:01 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-04-26 20:25:53 +02:00
|
|
|
"flag"
|
2017-04-15 17:08:01 +02:00
|
|
|
"github.com/zrepl/zrepl/sshbytestream"
|
|
|
|
"github.com/zrepl/zrepl/util"
|
|
|
|
// "bytes"
|
|
|
|
_ "bufio"
|
|
|
|
// "strings"
|
|
|
|
"fmt"
|
2017-04-26 20:25:53 +02:00
|
|
|
"io"
|
2017-04-15 17:08:01 +02:00
|
|
|
"os"
|
2017-04-26 20:25:53 +02:00
|
|
|
_ "time"
|
2017-04-15 17:08:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
mode := flag.String("mode", "", "incoming|outgoing")
|
|
|
|
incomingFile := flag.String("incoming.file", "", "file to deliver to callers")
|
|
|
|
outgoingHost := flag.String("outgoing.sshHost", "", "ssh host")
|
|
|
|
outgoingUser := flag.String("outgoing.sshUser", "", "ssh user")
|
2017-04-30 16:09:41 +02:00
|
|
|
outgoingIdentity := flag.String("outgoing.sshIdentity", "", "ssh private key")
|
2017-04-15 17:08:01 +02:00
|
|
|
outgoingPort := flag.Uint("outgoing.sshPort", 22, "ssh port")
|
2017-04-30 16:09:41 +02:00
|
|
|
outgoingFile := flag.String("outgoing.File", "", "")
|
2017-04-15 17:08:01 +02:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case (*mode == "incoming"):
|
|
|
|
|
|
|
|
conn, err := sshbytestream.Incoming()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
file, err := os.Open(*incomingFile)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
chunker := chunking.NewChunker(file)
|
|
|
|
|
|
|
|
_, err = io.Copy(conn, &chunker)
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(os.Stderr, "Chunk Count: %d\n", chunker.ChunkCount)
|
|
|
|
|
|
|
|
case *mode == "outgoing":
|
|
|
|
|
2017-04-30 16:09:41 +02:00
|
|
|
conn, err := sshbytestream.Outgoing(sshbytestream.SSHTransport{
|
|
|
|
Host: *outgoingHost,
|
|
|
|
User: *outgoingUser,
|
|
|
|
IdentityFile: *outgoingIdentity,
|
|
|
|
Port: uint16(*outgoingPort),
|
2017-04-15 17:08:01 +02:00
|
|
|
})
|
2017-04-30 16:09:41 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-04-15 17:08:01 +02:00
|
|
|
|
2017-04-30 16:09:41 +02:00
|
|
|
f, err := os.OpenFile(*outgoingFile, os.O_WRONLY, 0600)
|
2017-04-15 17:08:01 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
unchunker := chunking.NewUnchunker(conn)
|
|
|
|
|
2017-04-30 16:09:41 +02:00
|
|
|
_, err = io.Copy(f, unchunker)
|
2017-04-15 17:08:01 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
conn.Close()
|
|
|
|
|
|
|
|
fmt.Fprintf(os.Stderr, "Chunk Count: %d\n", unchunker.ChunkCount)
|
|
|
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic("unsupported mode!")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-26 20:25:53 +02:00
|
|
|
}
|