Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "log"
- "os"
- "time"
- "golang.org/x/crypto/ssh"
- )
- const (
- user = "root"
- pass = "somepass"
- ip = "192.168.1.1:22"
- )
- func main() {
- config := &ssh.ClientConfig{
- User: user,
- Auth: []ssh.AuthMethod{
- ssh.Password(pass),
- },
- Config: ssh.Config{
- Ciphers: []string{"aes128-cbc"}, // insecure!!
- },
- }
- client, err := ssh.Dial("tcp", ip, config)
- checkError(err, "ssh.Dial()")
- session, err := client.NewSession()
- defer session.Close()
- checkError(err, "client.NewSession()")
- modes := ssh.TerminalModes{
- ssh.ECHO: 1, // disable echoing
- ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud
- ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud
- }
- if err = session.RequestPty("vt100", 80, 40, modes); err != nil {
- log.Fatal(err)
- }
- //session.Stdin = os.Stdin
- in, _ := session.StdinPipe()
- //session.Stdout = os.Stdout.
- session.Stderr = os.Stderr
- if err = session.Shell(); err != nil {
- log.Fatal(err)
- }
- fmt.Println("Backing up Faura1...")
- //fmt.Println(buff.String())
- time.Sleep(time.Second * 2)
- in.Write([]byte("enable\n"))
- time.Sleep(time.Second * 1)
- //fmt.Println(buff.String()) // print the output
- in.Write([]byte("config\n"))
- time.Sleep(time.Second * 1)
- in.Write([]byte("backup data ftp 192.168.1.2 f1-olt.dat\n"))
- time.Sleep(time.Second * 1)
- in.Write([]byte("y\n"))
- time.Sleep(time.Second * 5)
- in.Write([]byte("backup configuration ftp 192.168.1.2 f1-olt.cfg\n"))
- time.Sleep(time.Second * 1)
- in.Write([]byte("y\n"))
- time.Sleep(time.Second * 5)
- os.Exit(1)
- err = session.Wait()
- if err != nil {
- panic(err)
- }
- }
- func checkError(err error, info string) {
- if err != nil {
- fmt.Printf("%s. error: %s\n", info, err)
- os.Exit(1)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement