當前位置: 首頁>>代碼示例>>Python>>正文


Python scp.SCPClient方法代碼示例

本文整理匯總了Python中scp.SCPClient方法的典型用法代碼示例。如果您正苦於以下問題:Python scp.SCPClient方法的具體用法?Python scp.SCPClient怎麽用?Python scp.SCPClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scp的用法示例。


在下文中一共展示了scp.SCPClient方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sftp_put

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def sftp_put(self, src, dest):
        """ Puts a file to the remote server

            Arguments:
            - src: Source local file to copy.
            - dest: Destination path in the remote server.
        """
        client, proxy = self.connect()
        transport = client.get_transport()
        try:
            sftp = paramiko.SFTPClient.from_transport(transport)
            if not transport.active:
                sftp = scp.SCPClient(transport)
        except Exception:
            # in case of failure try to use scp
            sftp = scp.SCPClient(transport)
        sftp.put(src, dest)
        sftp.close()
        if proxy:
            proxy.close()
        transport.close() 
開發者ID:grycap,項目名稱:im,代碼行數:23,代碼來源:SSH.py

示例2: _scp_put

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def _scp_put(self, hostname=None, username=None, password=None, srcfile=None, destfile=None):
        """SCP Put file

        :param hostname: FQDN/IP
        :param username: Username
        :param password: Password
        :param srcfile: Source file
        :param destfile: Destination file
        """
        self.ssh_client.connect(hostname=hostname,
                                username=username,
                                password=password)
        scp_client = scp.SCPClient(self.ssh_client.get_transport())
        if '*' in srcfile:
            listing = glob.glob(srcfile)
            if len(listing) == 0:
                raise Exception("No file found: " + srcfile)
            srcfile = listing
        scp_client.put(srcfile, destfile, recursive=True)
        scp_client.close() 
開發者ID:MissionCriticalCloud,項目名稱:bubble-toolkit,代碼行數:22,代碼來源:Base.py

示例3: fetch_remote_crashes

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def fetch_remote_crashes(self):
        """
        some exception handling code is taken from https://www.programcreek.com/python/example/105570/scp.SCPClient
        """
        try:
            ssh = SSHClient()
            ssh.load_system_host_keys()
            ssh.connect(hostname=config.remote_system_ip)
            self.copy_crashes_dir_with_scp(ssh)
        except AuthenticationException:
            print("Authentication failed, please verify your credentials: %s")
        except SSHException as sshException:
            print("Unable to establish SSH connection: %s" % sshException)
        except BadHostKeyException as badHostKeyException:
            print("Unable to verify server's host key: %s" % badHostKeyException)
        finally:
            ssh.close() 
開發者ID:fkie-cad,項目名稱:LuckyCAT,代碼行數:19,代碼來源:RemoteCrashFetcher.py

示例4: sftp_get

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def sftp_get(self, src, dest):
        """ Gets a file from the remote server

            Arguments:
            - src: Source file in the remote server.
            - dest: Local destination path to copy.
        """
        client, proxy = self.connect()
        transport = client.get_transport()

        try:
            sftp = paramiko.SFTPClient.from_transport(transport)
            if not transport.active:
                sftp = scp.SCPClient(transport)
        except Exception:
            # in case of failure try to use scp
            sftp = scp.SCPClient(transport)

        sftp.get(src, dest)
        sftp.close()
        if proxy:
            proxy.close()
        transport.close() 
開發者ID:grycap,項目名稱:im,代碼行數:25,代碼來源:SSH.py

示例5: sftp_get_files

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def sftp_get_files(self, src, dest):
        """ Gets a list of files from the remote server

            Arguments:
            - src: A list with the source files in the remote server.
            - dest: A list with the local destination paths to copy.
        """
        client, proxy = self.connect()
        transport = client.get_transport()
        try:
            sftp = paramiko.SFTPClient.from_transport(transport)
            if not transport.active:
                sftp = scp.SCPClient(transport)
        except Exception:
            # in case of failure try to use scp
            sftp = scp.SCPClient(transport)

        for file0, file1 in zip(src, dest):
            sftp.get(file0, file1)
        sftp.close()
        if proxy:
            proxy.close()
        transport.close() 
開發者ID:grycap,項目名稱:im,代碼行數:25,代碼來源:SSH.py

示例6: sftp_put_files

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def sftp_put_files(self, files):
        """ Puts a list of files to the remote server

            Arguments:
            - files: A tuple where the first elements is the local source file to copy and the second
                     element the destination paths in the remote server.
        """
        client, proxy = self.connect()
        transport = client.get_transport()
        try:
            sftp = paramiko.SFTPClient.from_transport(transport)
            if not transport.active:
                sftp = scp.SCPClient(transport)
        except Exception:
            # in case of failure try to use scp
            sftp = scp.SCPClient(transport)

        for src, dest in files:
            sftp.put(src, dest)
        sftp.close()
        if proxy:
            proxy.close()
        transport.close() 
開發者ID:grycap,項目名稱:im,代碼行數:25,代碼來源:SSH.py

示例7: copy_crashes_dir_with_scp

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def copy_crashes_dir_with_scp(self, ssh):
        parent_dir_of_crashes_dir = os.path.dirname(config.crashes_dir)
        try:
            scp = SCPClient(ssh.get_transport())
            scp.get(remote_path=config.remote_crashes_dir, local_path=parent_dir_of_crashes_dir, recursive=True,
                    preserve_times=True)
            print("successfully fetched!!")
        except SCPException as e:
            print("Operation error: %s" % e)
        except SocketTimeout:
            """
            the fetcher will need multiple attempts if the ssh connection is bad and/or the copy dir is big
            """
            print('SocketTimeout')
        except PipeTimeout as pipetimeout:
            print("timeout was reached on a read from a buffered Pipe: %s" % pipetimeout)
        finally:
            scp.close() 
開發者ID:fkie-cad,項目名稱:LuckyCAT,代碼行數:20,代碼來源:RemoteCrashFetcher.py

示例8: loginandcopydir

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def loginandcopydir(hostname,uname,pwd,sfile,tfile,recursive,preserve_times):
     try:
        log.info("Establishing ssh connection")
        client = getsshClient()
        client.load_system_host_keys()
        client.connect(hostname) #,username=uname)#,password=pwd)
     except paramiko.AuthenticationException:
        print("Authentication failed, please verify your credentials: %s")
     except paramiko.SSHException as sshException:
        print("Unable to establish SSH connection: %s" % sshException)
     except paramiko.BadHostKeyException as badHostKeyException:
        print("Unable to verify server's host key: %s" % badHostKeyException)
     except Exception as e:
        print(e.args)
     try:
        scpclient = scp.SCPClient(client.get_transport())
        scpclient.put(sfile,tfile,recursive,preserve_times)
     except scp.SCPException as e:
        print("Operation error: %s", e)

# Deprecated 
開發者ID:WiproOpenSource,項目名稱:galaxia,代碼行數:23,代碼來源:paramiko_helper.py

示例9: loginandcopy

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def loginandcopy(hostname,uname,pwd,sfile,tfile):
     try:
        log.info("Establishing ssh connection")
        client = getsshClient()
        client.load_system_host_keys()
        client.connect(hostname)#,username=uname)#,password=pwd)
     except paramiko.AuthenticationException:
        print("Authentication failed, please verify your credentials: %s")
     except paramiko.SSHException as sshException:
        print("Unable to establish SSH connection: %s" % sshException)
     except paramiko.BadHostKeyException as badHostKeyException:
        print("Unable to verify server's host key: %s" % badHostKeyException)
     except Exception as e:
        print(e.args)
     try:
        log.info("Getting SCP Client")
        scpclient = scp.SCPClient(client.get_transport())
        log.info(scpclient)
        log.info("Hostname: %s", hostname)
        log.info("source file: %s", sfile)
        log.info("target file: %s", tfile)
        scpclient.put(sfile,tfile)
     except scp.SCPException as e:
        print("Operation error: %s", e) 
開發者ID:WiproOpenSource,項目名稱:galaxia,代碼行數:26,代碼來源:paramiko_helper.py

示例10: transfer_file

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def transfer_file(self, ssh_client, files):
        if self.protocol == "sftp":
            with SFTPClient.from_transport(
                ssh_client.get_transport(),
                window_size=self.window_size,
                max_packet_size=self.max_transfer_size,
            ) as sftp:
                sftp.get_channel().settimeout(self.timeout)
                for source, destination in files:
                    getattr(sftp, self.direction)(source, destination)
        else:
            with SCPClient(
                ssh_client.get_transport(), socket_timeout=self.timeout
            ) as scp:
                for source, destination in files:
                    getattr(scp, self.direction)(source, destination) 
開發者ID:eNMS-automation,項目名稱:eNMS,代碼行數:18,代碼來源:automation.py

示例11: disconnect

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def disconnect(self):
        """ Close the connection(s) to the device.

        Purpose: Closes the current connection(s) to the device, no matter
               | what types exist.

        @returns: None
        @rtype: None
        """
        if self._shell:
            self._shell.close()
            self._shell = ""
        if isinstance(self._session, manager.Manager):
            self._session.close_session()
        elif isinstance(self._session, paramiko.client.SSHClient):
            self._session.close()
            self._session = ""
        elif isinstance(self._session, SCPClient):
            self._session.close()
            self._session = ""
            self._scp = "" 
開發者ID:NetworkAutomation,項目名稱:jaide,代碼行數:23,代碼來源:core.py

示例12: request_scp_transfer

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def request_scp_transfer(self):
        """ Begins SCP file transfer with progress """
        self.ensure_scp()
        self._init_transfer()
        source = self.upgrade_image_src_path
        dest = self.upgrade_image_dest_path
        ssh_connect_params = self.ft.ssh_ctl_chan._connect_params_dict()
        self.ft.scp_conn = self.ft.ssh_ctl_chan._build_ssh_client()
        self.ft.scp_conn.connect(**ssh_connect_params)
        with tqdm(unit="b", unit_scale=True, ascii=True) as t:
            self.progress = self._scp_tqdm(t)
            self.ft.scp_client = scp.SCPClient(
                self.ft.scp_conn.get_transport(), progress=self.progress
            )
            self.ft.scp_client.put(source, dest) 
開發者ID:austind,項目名稱:iosfw,代碼行數:17,代碼來源:iosfw.py

示例13: scp_push_file

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def scp_push_file(client, client_ftp, transfer_file, local_dir, remote_dir,
    CLOBBER=False, VERBOSE=False, LIST=False, MODE=0o775):
    #-- local and remote versions of file
    local_file = os.path.join(local_dir,transfer_file)
    remote_file = posixpath.join(remote_dir,transfer_file)
    #-- check if local file is newer than the remote file
    TEST = False
    OVERWRITE = 'clobber'
    if (transfer_file in client_ftp.listdir(remote_dir)):
        local_mtime = os.stat(local_file).st_mtime
        remote_mtime = client_ftp.stat(remote_file).st_mtime
        #-- if local file is newer: overwrite the remote file
        if (even(local_mtime) > even(remote_mtime)):
            TEST = True
            OVERWRITE = 'overwrite'
    else:
        TEST = True
        OVERWRITE = 'new'
    #-- if file does not exist remotely, is to be overwritten, or CLOBBER is set
    if TEST or CLOBBER:
        if VERBOSE or LIST:
            print('{0} --> '.format(local_file))
            print('\t{0} ({1})\n'.format(remote_file,OVERWRITE))
        #-- if not only listing files
        if not LIST:
            #-- copy local files to remote server
            with scp.SCPClient(client.get_transport(), socket_timeout=20) as s:
                s.put(local_file, remote_file, preserve_times=True)
            #-- change the permissions level of the transported file to MODE
            client_ftp.chmod(remote_file, MODE)

#-- PURPOSE: pull file from a remote host checking if file exists locally
#-- and if the remote file is newer than the local file (reprocessed)
#-- set the permissions mode of the local transferred file to MODE 
開發者ID:tsutterley,項目名稱:read-ICESat-2,代碼行數:36,代碼來源:scp_ICESat2_files.py

示例14: scp_pull_file

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def scp_pull_file(client, client_ftp, transfer_file, local_dir, remote_dir,
    CLOBBER=False, VERBOSE=False, LIST=False, MODE=0o775):
    #-- local and remote versions of file
    local_file = os.path.join(local_dir,transfer_file)
    remote_file = posixpath.join(remote_dir,transfer_file)
    #-- check if remote file is newer than the local file
    TEST = False
    OVERWRITE = 'clobber'
    if os.access(local_file, os.F_OK):
        local_mtime = os.stat(local_file).st_mtime
        remote_mtime = client_ftp.stat(remote_file).st_mtime
        #-- if remote file is newer: overwrite the local file
        if (even(remote_mtime) > even(local_mtime)):
            TEST = True
            OVERWRITE = 'overwrite'
    else:
        TEST = True
        OVERWRITE = 'new'
    #-- if file does not exist locally, is to be overwritten, or CLOBBER is set
    if TEST or CLOBBER:
        if VERBOSE or LIST:
            print('{0} --> '.format(remote_file))
            print('\t{0} ({1})\n'.format(local_file,OVERWRITE))
        #-- if not only listing files
        if not LIST:
            #-- copy local files from remote server
            with scp.SCPClient(client.get_transport(), socket_timeout=20) as s:
                s.get(remote_file, local_path=local_file, preserve_times=True)
            #-- change the permissions level of the transported file to MODE
            os.chmod(local_file, MODE)

#-- PURPOSE: rounds a number to an even number less than or equal to original 
開發者ID:tsutterley,項目名稱:read-ICESat-2,代碼行數:34,代碼來源:scp_ICESat2_files.py

示例15: provision_file_put

# 需要導入模塊: import scp [as 別名]
# 或者: from scp import SCPClient [as 別名]
def provision_file_put(ssh_client, local_file, remote_file):
    print "put", local_file, remote_file
    scp_client = scp.SCPClient(ssh_client.get_transport())
    scp_client.put(local_file, remote_file)
    scp_client.close() 
開發者ID:monetate,項目名稱:ectou-export,代碼行數:7,代碼來源:export.py


注:本文中的scp.SCPClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。