当前位置: 首页>>代码示例>>Python>>正文


Python pysftp.Connection方法代码示例

本文整理汇总了Python中pysftp.Connection方法的典型用法代码示例。如果您正苦于以下问题:Python pysftp.Connection方法的具体用法?Python pysftp.Connection怎么用?Python pysftp.Connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pysftp的用法示例。


在下文中一共展示了pysftp.Connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_conn

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def get_conn(self) -> pysftp.Connection:
        """
        Returns an SFTP connection object
        """
        if self.conn is None:
            cnopts = pysftp.CnOpts()
            if self.no_host_key_check:
                cnopts.hostkeys = None
            cnopts.compression = self.compress
            conn_params = {
                'host': self.remote_host,
                'port': self.port,
                'username': self.username,
                'cnopts': cnopts
            }
            if self.password and self.password.strip():
                conn_params['password'] = self.password
            if self.key_file:
                conn_params['private_key'] = self.key_file
            if self.private_key_pass:
                conn_params['private_key_pass'] = self.private_key_pass

            self.conn = pysftp.Connection(**conn_params)
        return self.conn 
开发者ID:apache,项目名称:airflow,代码行数:26,代码来源:sftp.py

示例2: write

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def write(self, dump_path, group_key=None, file_name=None):
        import pysftp
        if group_key is None:
            group_key = []

        filebase_path, file_name = self.create_filebase_name(group_key, file_name=file_name)
        destination = (filebase_path + '/' + file_name)
        self.logger.info('Start uploading to {}'.format(dump_path))
        with pysftp.Connection(self.sftp_host, port=self.sftp_port,
                               username=self.sftp_user,
                               password=self.sftp_password) as sftp:
            if not sftp.exists(filebase_path):
                sftp.makedirs(filebase_path)
            progress = SftpUploadProgress(self.logger)
            sftp.put(dump_path, destination, callback=progress)
        self.last_written_file = destination
        self._update_metadata(dump_path, destination)
        self.logger.info('Saved {}'.format(dump_path)) 
开发者ID:scrapinghub,项目名称:exporters,代码行数:20,代码来源:sftp_writer.py

示例3: get_file_sftp

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def get_file_sftp(host, path_to_file, sftp_configuration):
    """
        Copy an existing file from SFTP via sftp://*host*/*path_to_file* link to a home directory.
        The function return the full path to the file that has been downloaded.
    """
    # disable host key checking
    cnopts = pysftp.CnOpts()
    cnopts.hostkeys = None

    # construct SFTP object and get the file on a server
    with pysftp.Connection(host, username = sftp_configuration["user"], password = sftp_configuration["psswd"],
                           cnopts = cnopts) as sftp:
        sftp.get(path_to_file)

    file_location = gc_write_dir + "/" + re.findall("[^/]*$", path_to_file)[0]
    print("File " + path_to_file + " has got successfully.")
    return file_location 
开发者ID:OWOX,项目名称:BigQuery-integrations,代码行数:19,代码来源:main.py

示例4: _check_write_consistency

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def _check_write_consistency(self):
        import pysftp
        with pysftp.Connection(self.sftp_host, port=self.sftp_port,
                               username=self.sftp_user,
                               password=self.sftp_password) as sftp:
            for file_info in self.get_metadata('files_written'):
                try:
                    sftp_info = sftp.stat(file_info['filename'])
                except IOError as e:
                    if e.errno == errno.ENOENT:
                        raise InconsistentWriteState(
                            '{} file is not present at destination'.format(file_info['filename']))
                sftp_size = sftp_info.st_size
                if sftp_size != file_info['size']:
                    raise InconsistentWriteState('Wrong size for file {}. Expected: {} - got {}'
                                                 .format(file_info['filename'], file_info['size'],
                                                         sftp_size))
        self.logger.info('Consistency check passed') 
开发者ID:scrapinghub,项目名称:exporters,代码行数:20,代码来源:sftp_writer.py

示例5: sftpc

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def sftpc(self):

        args_use = self.provider.args
        if len(self.args):
            args_use = self.args

        kwargs_use = {}
        kwargs_use['host'] = self.host
        kwargs_use['port'] = int(self.port) if self.port else 22
        for k, v in self.provider.kwargs.items():
            kwargs_use[k] = v
        for k, v in self.kwargs.items():
            kwargs_use[k] = v

        conn = pysftp.Connection(*args_use, **kwargs_use)
        yield conn
        conn.close() 
开发者ID:cgat-developers,项目名称:cgat-core,代码行数:19,代码来源:sftp.py

示例6: _sftp_connect

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def _sftp_connect(self):
        try:
            self.conn.pwd
            return True
        except:
            try:
                import pysftp
            except ImportError:
                raise ModuleNotFoundError('Please install pysftp to use SFTP.')

            self.conn = pysftp.Connection(self.host, username=self.username, password=self.password,
                                          port=self.port, **self.pysftp_conn_kwargs) 
开发者ID:d6t,项目名称:d6tpipe,代码行数:14,代码来源:ftp.py

示例7: connect

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def connect(self):
        """
            Establishes the actual connection to the referred RSE.

            :param: credentials needed to establish a connection with the stroage.

            :raises RSEAccessDenied: if no connection could be established.
        """
        try:
            self.rse['credentials']['host'] = self.attributes['hostname']
            self.__connection = pysftp.Connection(**self.rse['credentials'])
        except Exception as e:
            raise exception.RSEAccessDenied(e) 
开发者ID:rucio,项目名称:rucio,代码行数:15,代码来源:sftp.py

示例8: setupClass

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def setupClass(cls):
        """SFTP (RSE/PROTOCOLS): Creating necessary directories and files """
        # Creating local files
        cls.tmpdir = tempfile.mkdtemp()
        cls.user = uuid()

        with open("%s/data.raw" % cls.tmpdir, "wb") as out:
            out.seek((1024 * 1024) - 1)  # 1 MB
            out.write('\0')
        for fil in MgrTestCases.files_local:
            os.symlink('%s/data.raw' % cls.tmpdir, '%s/%s' % (cls.tmpdir, fil))

        # Load local credentials from file
        with open('etc/rse-accounts.cfg') as fil:
            data = json.load(fil)
        credentials = data['LXPLUS']
        lxplus = pysftp.Connection(**credentials)
        with open('etc/rse_repository.json') as fil:
            prefix = json.load(fil)['LXPLUS']['protocols']['supported']['sftp']['prefix']
        lxplus.execute('mkdir %s' % prefix)
        lxplus.execute('dd if=/dev/urandom of=%s/data.raw bs=1024 count=1024' % prefix)
        cls.static_file = 'sftp://lxplus.cern.ch:22%sdata.raw' % prefix
        protocol = mgr.create_protocol(mgr.get_rse_info('LXPLUS'), 'write')
        for fil in MgrTestCases.files_remote:
            tmp = protocol.parse_pfns(protocol.lfns2pfns({'name': fil, 'scope': 'user.%s' % cls.user}).values()[0]).values()[0]
            for cmd in ['mkdir -p %s' % ''.join([tmp['prefix'], tmp['path']]), 'ln -s %sdata.raw %s' % (prefix, ''.join([tmp['prefix'], tmp['path'], tmp['name']]))]:
                lxplus.execute(cmd)
        lxplus.close() 
开发者ID:rucio,项目名称:rucio,代码行数:30,代码来源:test_rse_protocol_sftp.py

示例9: tearDownClass

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def tearDownClass(cls):
        """SFTP (RSE/PROTOCOLS): Removing created directorie s and files """
        # Load local creditentials from file
        credentials = {}
        with open('etc/rse-accounts.cfg') as fil:
            data = json.load(fil)
        credentials = data['LXPLUS']
        lxplus = pysftp.Connection(**credentials)
        with open('etc/rse_repository.json') as fil:
            prefix = json.load(fil)['LXPLUS']['protocols']['supported']['sftp']['prefix']
        lxplus.execute('rm -rf %s' % prefix)
        lxplus.close()
        shutil.rmtree(cls.tmpdir) 
开发者ID:rucio,项目名称:rucio,代码行数:15,代码来源:test_rse_protocol_sftp.py

示例10: update_connection

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def update_connection(self, login, session=None):
        connection = (session.query(Connection).
                      filter(Connection.conn_id == "sftp_default")
                      .first())
        old_login = connection.login
        connection.login = login
        session.commit()
        return old_login 
开发者ID:apache,项目名称:airflow,代码行数:10,代码来源:test_sftp.py

示例11: test_get_conn

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def test_get_conn(self):
        output = self.hook.get_conn()
        self.assertEqual(type(output), pysftp.Connection) 
开发者ID:apache,项目名称:airflow,代码行数:5,代码来源:test_sftp.py

示例12: test_no_host_key_check_default

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def test_no_host_key_check_default(self, get_connection):
        connection = Connection(login='login', host='host')
        get_connection.return_value = connection
        hook = SFTPHook()
        self.assertEqual(hook.no_host_key_check, False) 
开发者ID:apache,项目名称:airflow,代码行数:7,代码来源:test_sftp.py

示例13: test_no_host_key_check_enabled

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def test_no_host_key_check_enabled(self, get_connection):
        connection = Connection(
            login='login', host='host',
            extra='{"no_host_key_check": true}')

        get_connection.return_value = connection
        hook = SFTPHook()
        self.assertEqual(hook.no_host_key_check, True) 
开发者ID:apache,项目名称:airflow,代码行数:10,代码来源:test_sftp.py

示例14: test_no_host_key_check_disabled

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def test_no_host_key_check_disabled(self, get_connection):
        connection = Connection(
            login='login', host='host',
            extra='{"no_host_key_check": false}')

        get_connection.return_value = connection
        hook = SFTPHook()
        self.assertEqual(hook.no_host_key_check, False) 
开发者ID:apache,项目名称:airflow,代码行数:10,代码来源:test_sftp.py

示例15: test_no_host_key_check_ignore

# 需要导入模块: import pysftp [as 别名]
# 或者: from pysftp import Connection [as 别名]
def test_no_host_key_check_ignore(self, get_connection):
        connection = Connection(
            login='login', host='host',
            extra='{"ignore_hostkey_verification": true}')

        get_connection.return_value = connection
        hook = SFTPHook()
        self.assertEqual(hook.no_host_key_check, True) 
开发者ID:apache,项目名称:airflow,代码行数:10,代码来源:test_sftp.py


注:本文中的pysftp.Connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。