simple_ssh

package module
v0.0.0-...-e6f7652 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

README

simple ssh server library

example:

package main

import (
	"fmt"
	"time"

	ssh "github.com/imatakatsu/simple-ssh"
)

var srv ssh.Serv

func main() {
	err := srv.Init(terminal)
	if err != nil {
		fmt.Println(err)
		return
	}
	srv.Listen(":2222")
}

func terminal(conn ssh.SshConn) {
	defer conn.Close()
	conn.Writeln("\x1bcWelcome to Simple SSH Example!!! wooow")
	conn.Writef("here u can write (some data: %v) formatted strings!!\r\n", time.Now())
	conn.Write("\r\nit`s an ssh echo server, lolll\r\n\r\n")
	for {
		ans, err := conn.Readline()
		if err != nil {
			fmt.Println(err)
			return
		}
		if ans == "exit" || ans == "q" {
			conn.Writeln("byee")
			return
		}
		conn.Writeln("you wrote:", ans)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Serv

type Serv struct {
	KeyFile  string
	Config   *ssh.ServerConfig
	Listener *net.Listener
	Handler  ServHandler
}

func (*Serv) Init

func (s *Serv) Init(handler ServHandler) error

func (*Serv) Listen

func (s *Serv) Listen(host string) error

type ServHandler

type ServHandler func(c SshConn)

type SshConn

type SshConn struct {
	// contains filtered or unexported fields
}

func (*SshConn) Close

func (s *SshConn) Close() error

func (*SshConn) Readline

func (s *SshConn) Readline() (string, error)

func (*SshConn) Write

func (s *SshConn) Write(a ...any) error

func (*SshConn) Writef

func (s *SshConn) Writef(f string, a ...any) error

func (*SshConn) Writeln

func (s *SshConn) Writeln(a ...any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL