<commit_before><?php

namespace League\Flysystem\Adapter;

use Net_SFTP;
use Crypt_RSA;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Util;
use LogicException;
use InvalidArgumentException;

class Sftp extends AbstractFtpAdapter
{
    protected $port = 22;
    protected $privatekey;
    protected $configurable = array('host', 'port', 'username', 'password', 'timeout', 'root', 'privateKey', 'permPrivate', 'permPublic');
    protected $statMap = array('mtime' => 'timestamp', 'size' => 'size');

    protected function prefix($path)
    {
        return $this->root.ltrim($path, $this->separator);
    }

    public function setPrivateKey($key)
    {
        $this->privatekey = $key;

        return $this;
    }

    public function setNetSftpConnection(Net_SFTP $connection)
    {
        $this->connection = $connection;

        return $this;
    }

    public function connect()
    {
        $this->connection = $this->connection ?: new Net_SFTP($this->host, $this->port, $this->timeout);

        if ( ! $this->connection->isConnected()) {
            throw new LogicException('Could not connect to host: '.$this->host);
        }

        $this->login();
        $this->setConnectionRoot();
    }

    protected function login()
    {
        if ( ! $this->connection->login($this->username, $this->getPassword())) {
            throw new LogicException('Could not login with username: '.$this->username.', host: '.$this->host);
        }
    }

    protected function setConnectionRoot()
    {
        if ($this->root) {
            $this->connection->chdir($this->root);
        }
    }

    public function getPassword()
    {
        if ($this->privatekey) {
            return $this->getPrivateKey();
        }

        return $this->password;
    }<commit_msg>Changing the connection determination logic so it will not error on a fresh connection.<commit_after><?php

namespace League\Flysystem\Adapter;

use Net_SFTP;
use Crypt_RSA;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Util;
use LogicException;
use InvalidArgumentException;

class Sftp extends AbstractFtpAdapter
{
    protected $port = 22;
    protected $privatekey;
    protected $configurable = array('host', 'port', 'username', 'password', 'timeout', 'root', 'privateKey', 'permPrivate', 'permPublic');
    protected $statMap = array('mtime' => 'timestamp', 'size' => 'size');

    protected function prefix($path)
    {
        return $this->root.ltrim($path, $this->separator);
    }

    public function setPrivateKey($key)
    {
        $this->privatekey = $key;

        return $this;
    }

    public function setNetSftpConnection(Net_SFTP $connection)
    {
        $this->connection = $connection;

        return $this;
    }

    public function connect()
    {
        $this->connection = $this->connection ?: new Net_SFTP($this->host, $this->port, $this->timeout);

        if ( ! $this->connection ) {
            throw new LogicException('Could not connect to host: '.$this->host);
        }

        $this->login();
        $this->setConnectionRoot();
    }

    protected function login()
    {
        if ( ! $this->connection->login($this->username, $this->getPassword())) {
            throw new LogicException('Could not login with username: '.$this->username.', host: '.$this->host);
        }
    }

    protected function setConnectionRoot()
    {
        if ($this->root) {
            $this->connection->chdir($this->root);
        }
    }

    public function getPassword()
    {
        if ($this->privatekey) {
            return $this->getPrivateKey();
        }

        return $this->password;
    }
{'fraction_non_alphanumeric': 0.1441515650741351, 'fraction_numerical': 0.001098297638660077, 'mean_word_length': 2.690982776089159, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 60, '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': '4585467', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1019, 'n_words': 241}