github.com/devops-filetransfer/sshego@v7.0.4+incompatible/cmd/manual-test-client/client.go (about) 1 /* 2 a simple test client. Change the settings at the top of main() 3 to manually test your setup. 4 */ 5 package main 6 7 import ( 8 "context" 9 "fmt" 10 "os" 11 12 "github.com/glycerine/sshego" 13 ) 14 15 func main() { 16 // you'll have to set these to do 17 // manual testing. These are just guesses/to get you started. 18 19 home := os.Getenv("HOME") 20 user := os.Getenv("USER") 21 sshd := "example.com" // definitely must be changed. 22 target := "127.0.0.1:8888" 23 24 // N.B. we will append any newly seen hosts to this file 25 // if addNewHost is true. 26 kh := home + "/.ssh/known_hosts" 27 28 rsaPath := home + "/.ssh/id_rsa" // definitely must be set, unlikely to be correct as is. 29 addNewHost := false 30 31 // done with settings 32 dc := sshego.DialConfig{ 33 ClientKnownHostsPath: kh, 34 Mylogin: user, 35 RsaPath: rsaPath, 36 Sshdhost: sshd, 37 Sshdport: 22, 38 DownstreamHostPort: target, 39 TofuAddIfNotKnown: addNewHost, 40 } 41 42 skipDownstream := false 43 channelToTcpServer, _, _, err := dc.Dial(context.TODO(), nil, skipDownstream) 44 panicOn(err) 45 46 confirmationPayload := "ping" 47 m, err := channelToTcpServer.Write([]byte(confirmationPayload)) 48 panicOn(err) 49 if m != len(confirmationPayload) { 50 panic("too short a write!") 51 } 52 53 payloadByteCount := 4 54 confirmationReply := "pong" 55 56 // check reply 57 rep := make([]byte, payloadByteCount) 58 m, err = channelToTcpServer.Read(rep) 59 panicOn(err) 60 if m != payloadByteCount { 61 panic("too short a reply!") 62 } 63 srep := string(rep) 64 if srep != confirmationReply { 65 panic(fmt.Errorf("saw '%s' but expected '%s'", srep, confirmationReply)) 66 } 67 fmt.Printf("reply success! we got the expected srep reply '%s'\n", srep) 68 69 channelToTcpServer.Close() 70 } 71 72 func panicOn(err error) { 73 if err != nil { 74 panic(err) 75 } 76 }