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"
|
2017-05-14 15:58:33 +02:00
|
|
|
. "github.com/zrepl/zrepl/util"
|
2017-04-15 17:08:01 +02:00
|
|
|
// "bytes"
|
|
|
|
_ "bufio"
|
|
|
|
// "strings"
|
2017-04-26 20:25:53 +02:00
|
|
|
"io"
|
2017-05-03 18:32:11 +02:00
|
|
|
"log"
|
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)
|
|
|
|
}
|
|
|
|
|
2017-05-14 15:58:33 +02:00
|
|
|
chunker := NewChunker(file)
|
2017-04-15 17:08:01 +02:00
|
|
|
|
|
|
|
_, err = io.Copy(conn, &chunker)
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2017-05-03 18:32:11 +02:00
|
|
|
log.Printf("Chunk Count: %d\n", chunker.ChunkCount)
|
2017-04-15 17:08:01 +02:00
|
|
|
|
|
|
|
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-05-12 20:15:27 +02:00
|
|
|
f, err := os.OpenFile(*outgoingFile, os.O_CREATE|os.O_WRONLY, 0600)
|
2017-04-15 17:08:01 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2017-05-14 15:58:33 +02:00
|
|
|
unchunker := NewUnchunker(conn)
|
2017-04-15 17:08:01 +02:00
|
|
|
|
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()
|
|
|
|
|
2017-05-03 18:32:11 +02:00
|
|
|
log.Printf("Chunk Count: %d\n", unchunker.ChunkCount)
|
2017-04-15 17:08:01 +02:00
|
|
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic("unsupported mode!")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-26 20:25:53 +02:00
|
|
|
}
|