當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。