当前位置: 首页>>代码示例>>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;未经允许,请勿转载。