How to use the moler.cmd.unix.sftp.Sftp function in moler

To help you get started, we’ve selected a few moler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nokia / moler / test / unix / test_cmd_sftp.py View on Github external
def test_sftp_raises_file_error_no_such_file(buffer_connection, command_output_and_expected_result_no_such_file):
    command_output, expected_result = command_output_and_expected_result_no_such_file
    buffer_connection.remote_inject_response([command_output])
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection, host='192.168.0.102', user='fred', password='1234',
                    source_path='dog', destination_path='/home/xyz/Work/dog')
    with pytest.raises(CommandFailure):
        sftp_cmd()
github nokia / moler / test / unix / test_cmd_sftp.py View on Github external
def test_sftp_returns_result_of_fetching_file_with_progress_bar(buffer_connection,
                                                                command_output_and_expected_result_progress_bar):

    sftp_cmd = Sftp(connection=buffer_connection.moler_connection, host='192.168.0.102', user='fred', password='1234',
                    source_path="debian-9.5.0-i386-netinst.iso")
    assert "sftp fred@192.168.0.102:debian-9.5.0-i386-netinst.iso" == sftp_cmd.command_string
    command_output, expected_result = command_output_and_expected_result_progress_bar
    sftp_cmd.start()
    for output in command_output:
        buffer_connection.moler_connection.data_received(output.encode("utf-8"))
    assert sftp_cmd.current_ret == expected_result
    sftp_cmd.await_done()
    assert sftp_cmd.done() is True
github nokia / moler / test / unix / test_cmd_sftp.py View on Github external
def test_sftp_raise_not_confirmed_connection(buffer_connection, command_output_and_expected_result_not_confirmed):

    sftp_cmd = Sftp(connection=buffer_connection.moler_connection, host='192.168.0.102', user='fred', password='1234',
                    confirm_connection=False, command="mkdir", no_result=True)
    assert "sftp fred@192.168.0.102" == sftp_cmd.command_string
    sftp_cmd.start()
    command_output, expected_result = command_output_and_expected_result_not_confirmed
    for output in command_output:
        buffer_connection.moler_connection.data_received(output.encode("utf-8"))
    with pytest.raises(CommandFailure):
        sftp_cmd.await_done(timeout=2)
github nokia / moler / test / unix / test_cmd_sftp.py View on Github external
def test_sftp_raises_connection_error(buffer_connection, command_output_and_expected_result_connection_error):
    command_output, expected_result = command_output_and_expected_result_connection_error
    buffer_connection.remote_inject_response([command_output])
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection, host='192.168.0.102', user='fred', password='1234',
                    options='-6', command='get animals/pets/dog /root/dog')
    with pytest.raises(CommandFailure):
        sftp_cmd()
github nokia / moler / test / unix / test_cmd_sftp.py View on Github external
def test_sftp_returns_proper_command_string_new_pathname(buffer_connection):
    sftp_cmd = Sftp(connection=buffer_connection.moler_connection, host="myhost.com", user="fred", password='1234',
                    source_path="/home/fred/homework.txt", destination_path="/home/vivi/new_homework.txt")
    assert "sftp fred@myhost.com:/home/fred/homework.txt /home/vivi/new_homework.txt" == sftp_cmd.command_string
github nokia / moler / moler / cmd / unix / sftp.py View on Github external
def __init__(self, connection, host, password, user=None, confirm_connection=True, source_path=None,
                 destination_path=None, options=None, command=None, no_result=False, prompt=None, newline_chars=None,
                 timeout=60, runner=None):
        super(Sftp, self).__init__(connection=connection, prompt=prompt, newline_chars=newline_chars, runner=runner)

        # Attributes defined by calling the command
        self.host = host
        self.user = user
        self.password = password
        self.confirm_connection = confirm_connection

        self.source_path = source_path
        self.destination_path = destination_path

        self.options = options
        self.command = command
        self.no_result = no_result
        self.extend_timeout(timeout)

        # Internal variables
github nokia / moler / moler / cmd / unix / sftp.py View on Github external
def _parse_line_fetching_uploading(self, line):
        if self.ready_to_parse_line:
            if self._regex_helper.search_compiled(Sftp._re_fetching, line):
                if not self.sending_started:
                    self.current_ret['RESULT'] = list()
                self.sending_started = True
                self.current_ret['RESULT'].append(line)
                raise ParsingDone
            elif self.sending_started and self._regex_helper.search_compiled(Sftp._re_success_bar, line):
                self.current_ret['RESULT'].append(line)
                raise ParsingDone
            elif self.sending_started and self._regex_helper.search_compiled(Sftp._re_progress_bar, line):
                raise ParsingDone
            elif self.sending_started:
                self.set_exception(CommandFailure(self, "ERROR: {}".format(line)))
                raise ParsingDone
github nokia / moler / moler / cmd / unix / sftp.py View on Github external
def _authentication_failure(self, line):
        if self._regex_helper.search_compiled(Sftp._re_resend_password, line):
            self.password_sent = False
            raise ParsingDone
        elif self._regex_helper.search_compiled(Sftp._re_authentication, line):
            auth = self._regex_helper.group("AUTH")
            perm = self._regex_helper.group("PERM")
            self.set_exception(CommandFailure(self, "ERROR: {msg}".format(msg=auth if auth else perm)))
            raise ParsingDone
github nokia / moler / moler / cmd / unix / sftp.py View on Github external
def _parse_line_fetching_uploading(self, line):
        if self.ready_to_parse_line:
            if self._regex_helper.search_compiled(Sftp._re_fetching, line):
                if not self.sending_started:
                    self.current_ret['RESULT'] = list()
                self.sending_started = True
                self.current_ret['RESULT'].append(line)
                raise ParsingDone
            elif self.sending_started and self._regex_helper.search_compiled(Sftp._re_success_bar, line):
                self.current_ret['RESULT'].append(line)
                raise ParsingDone
            elif self.sending_started and self._regex_helper.search_compiled(Sftp._re_progress_bar, line):
                raise ParsingDone
            elif self.sending_started:
                self.set_exception(CommandFailure(self, "ERROR: {}".format(line)))
                raise ParsingDone
github nokia / moler / moler / cmd / unix / sftp.py View on Github external
def _parse_line_fetching_uploading(self, line):
        if self.ready_to_parse_line:
            if self._regex_helper.search_compiled(Sftp._re_fetching, line):
                if not self.sending_started:
                    self.current_ret['RESULT'] = list()
                self.sending_started = True
                self.current_ret['RESULT'].append(line)
                raise ParsingDone
            elif self.sending_started and self._regex_helper.search_compiled(Sftp._re_success_bar, line):
                self.current_ret['RESULT'].append(line)
                raise ParsingDone
            elif self.sending_started and self._regex_helper.search_compiled(Sftp._re_progress_bar, line):
                raise ParsingDone
            elif self.sending_started:
                self.set_exception(CommandFailure(self, "ERROR: {}".format(line)))
                raise ParsingDone