コード例 #1
0
ファイル: libssh.py プロジェクト: mgwilliams/python-libssh
    def put_file(self, remote_path, data, mode):
        remote_path = str(remote_path)
        path, filename = os.path.split(remote_path)

        scp = clibssh.ssh_scp_new(self.session, (clibssh.SSH_SCP_WRITE), path)
        if clibssh.ssh_scp_init(scp) != clibssh.SSH_OK:
            self.print_error("Cannot open scp session")
        clibssh.ssh_scp_close(scp)
        clibssh.ssh_scp_free(scp)

        scp = clibssh.ssh_scp_new(self.session, (clibssh.SSH_SCP_WRITE), path)
        if clibssh.ssh_scp_init(scp) != clibssh.SSH_OK:
            self.print_error("Cannot open scp session")
            return
        rc = clibssh.ssh_scp_push_file(scp, filename, len(data), mode)
        if rc != clibssh.SSH_OK:
            self.print_error("Cannot open remote file for writing")
            return
        if len(data):
            rc = clibssh.ssh_scp_write(scp, data, len(data))
            if rc != clibssh.SSH_OK:
                self.print_error("Cannot write to remote file")
        clibssh.ssh_scp_close(scp)
        clibssh.ssh_scp_free(scp)
        print "done"
        return clibssh.SSH_OK
コード例 #2
0
ファイル: libssh.py プロジェクト: mgwilliams/python-libssh
 def __init__(self, session):
     self.        rc = clibssh.ssh_scp_init(self.scp)
     self.session = session