<commit_before>package gossh

import (
	"bytes"
	"code.google.com/p/go.crypto/ssh"
	"compress/gzip"
	"crypto/sha256"
	"encoding/base64"
	"fmt"
	"log"
	"net"
	"net/http"
	"os"
	"os/exec"
	"path/filepath"
	"time"
)

func New(host, user string) (c *Client) {
	return &Client{
		User: user,
		Host: host,
	}
}

type Client struct {
	User        string
	Host        string
	Port        int
	Agent       net.Conn
	password    string
	Conn        *ssh.ClientConn
	DebugWriter Writer
	ErrorWriter Writer
	InfoWriter  Writer
}

func (c *Client) Password(user string) (password string, e error) {
	if c.password != "" {
		return c.password, nil
	}
	return "", fmt.Errorf("password must be set with SetPassword()")
}

func (c *Client) Close() {
	if c.Conn != nil {
		c.Conn.Close()
	}
	if c.Agent != nil {
		c.Agent.Close()
	}
}

func (client *Client) Attach() error {
	options := []string{"-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no"}
	if client.User != "" {
		options = append(options, "-l", client.User)
	}
	options = append(options, client.Host)
	log.Printf("executing %#v", options)
	cmd := exec.Command("/usr/bin/ssh", options...)
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
	cmd.Stdin = os.Stdin
	cmd.Env = os.Environ()
	return cmd.Run()
}

func (c *Client) SetPassword(password string) {
	c.password = password
}

func (c *Client) ConnectWhenNotConnected() (e error) {
	if c.Conn != nil {
		return nil
	}
	return c.Connect()
}

func (c *Client) Connect() (e error) {
	if c.Port == 0 {
		c.Port = 22
	}
	var auths []ssh.ClientAuth

	if c.password != "" {
		auths = append(auths, ssh.ClientAuthPassword(c))
	}

	if c.Agent, e = net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); e == nil {<commit_msg>add method to retrieve an active Connection<commit_after>package gossh

import (
	"bytes"
	"code.google.com/p/go.crypto/ssh"
	"compress/gzip"
	"crypto/sha256"
	"encoding/base64"
	"fmt"
	"log"
	"net"
	"net/http"
	"os"
	"os/exec"
	"path/filepath"
	"time"
)

func New(host, user string) (c *Client) {
	return &Client{
		User: user,
		Host: host,
	}
}

type Client struct {
	User        string
	Host        string
	Port        int
	Agent       net.Conn
	password    string
	Conn        *ssh.ClientConn
	DebugWriter Writer
	ErrorWriter Writer
	InfoWriter  Writer
}

func (c *Client) Password(user string) (password string, e error) {
	if c.password != "" {
		return c.password, nil
	}
	return "", fmt.Errorf("password must be set with SetPassword()")
}

func (c *Client) Close() {
	if c.Conn != nil {
		c.Conn.Close()
	}
	if c.Agent != nil {
		c.Agent.Close()
	}
}

func (client *Client) Attach() error {
	options := []string{"-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no"}
	if client.User != "" {
		options = append(options, "-l", client.User)
	}
	options = append(options, client.Host)
	log.Printf("executing %#v", options)
	cmd := exec.Command("/usr/bin/ssh", options...)
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
	cmd.Stdin = os.Stdin
	cmd.Env = os.Environ()
	return cmd.Run()
}

func (c *Client) SetPassword(password string) {
	c.password = password
}

func (c *Client) Connection() (*ssh.ClientConn, error) {
	if c.Conn != nil {
		return c.Conn, nil
	}
	e := c.Connect()
	if e != nil {
		return nil, e
	}
	return c.Conn, nil
}

func (c *Client) ConnectWhenNotConnected() (e error) {
	if c.Conn != nil {
		return nil
	}
	return c.Connect()
}

func (c *Client) Connect() (e error) {
	if c.Port == 0 {
		c.Port = 22
	}
	var auths []ssh.ClientAuth

	if c.password != "" {
		auths = append(auths, ssh.ClientAuthPassword(c))
	}

	if c.Agent, e = net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); e == nil {
{'fraction_non_alphanumeric': 0.16365131578947367, 'fraction_numerical': 0.0043859649122807015, 'mean_word_length': 3.297997644287397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4344252', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1415, 'n_words': 355}