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


Python ftplib.FTP_TLS屬性代碼示例

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


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

示例1: __init__

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def __init__(self, one=None, globus_client=None):
        super().__init__(one=one)
        self.ftp = ftplib.FTP_TLS(host=FTP_HOST,
                                  user=one._par.FTP_DATA_SERVER_LOGIN,
                                  passwd=one._par.FTP_DATA_SERVER_PWD)
        # self.ftp.ssl_version = ssl.PROTOCOL_TLSv1
        # self.ftp.auth()
        self.ftp.prot_p()
        self.ftp.login(one._par.FTP_DATA_SERVER_LOGIN, one._par.FTP_DATA_SERVER_PWD) 
開發者ID:int-brain-lab,項目名稱:ibllib,代碼行數:11,代碼來源:patcher.py

示例2: connect

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def connect(self, params={}):
        self.logger.info("Connect: Connecting..")
        host = params.get('host')
        username = params.get('credentials').get('username', 'anonymous')
        password = params.get('credentials').get('password', 'test@test.com')
        # Use secure mode?
        secure = params.get('secure', False)
        # Use passive mode?
        passive = params.get('passive', False)

        # Either ftplib.FTP or ftplib.FTP_TLS
        base_ftp_class = ftplib.FTP
        if secure:
            base_ftp_class = ftplib.FTP_TLS
        my_session_factory = ftputil.session.session_factory(
            base_class=base_ftp_class,
            use_passive_mode=passive)
        try:
            self.ftp_host = ftputil.FTPHost(host, username,
                                            password, session_factory=my_session_factory)
        except ftputil.error.PermanentError as e:
            raise e 
開發者ID:rapid7,項目名稱:insightconnect-plugins,代碼行數:24,代碼來源:connection.py

示例3: test_context

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def test_context(self):
        self.client.quit()
        ctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
        self.assertRaises(ValueError, ftplib.FTP_TLS, keyfile=CERTFILE,
                          context=ctx)
        self.assertRaises(ValueError, ftplib.FTP_TLS, certfile=CERTFILE,
                          context=ctx)
        self.assertRaises(ValueError, ftplib.FTP_TLS, certfile=CERTFILE,
                          keyfile=CERTFILE, context=ctx)

        self.client = ftplib.FTP_TLS(context=ctx, timeout=TIMEOUT)
        self.client.connect(self.server.host, self.server.port)
        self.assertNotIsInstance(self.client.sock, ssl.SSLSocket)
        self.client.auth()
        self.assertIs(self.client.sock.context, ctx)
        self.assertIsInstance(self.client.sock, ssl.SSLSocket)

        self.client.prot_p()
        sock = self.client.transfercmd('list')
        try:
            self.assertIs(sock.context, ctx)
            self.assertIsInstance(sock, ssl.SSLSocket)
        finally:
            sock.close() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_ftplib.py

示例4: get_conn

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def get_conn(self):
        """
        Returns a FTPS connection object.
        """
        if self.conn is None:
            params = self.get_connection(self.ftp_conn_id)
            pasv = params.extra_dejson.get("passive", True)

            if params.port:
                ftplib.FTP_TLS.port = params.port

            self.conn = ftplib.FTP_TLS(
                params.host, params.login, params.password
            )
            self.conn.set_pasv(pasv)

        return self.conn 
開發者ID:apache,項目名稱:airflow,代碼行數:19,代碼來源:ftp.py

示例5: test_context

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def test_context(self):
        self.client.quit()
        ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        self.assertRaises(ValueError, ftplib.FTP_TLS, keyfile=CERTFILE,
                          context=ctx)
        self.assertRaises(ValueError, ftplib.FTP_TLS, certfile=CERTFILE,
                          context=ctx)
        self.assertRaises(ValueError, ftplib.FTP_TLS, certfile=CERTFILE,
                          keyfile=CERTFILE, context=ctx)

        self.client = ftplib.FTP_TLS(context=ctx, timeout=TIMEOUT)
        self.client.connect(self.server.host, self.server.port)
        self.assertNotIsInstance(self.client.sock, ssl.SSLSocket)
        self.client.auth()
        self.assertIs(self.client.sock.context, ctx)
        self.assertIsInstance(self.client.sock, ssl.SSLSocket)

        self.client.prot_p()
        with self.client.transfercmd('list') as sock:
            self.assertIs(sock.context, ctx)
            self.assertIsInstance(sock, ssl.SSLSocket) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:23,代碼來源:test_ftplib.py

示例6: test_context

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def test_context(self):
        self.client.quit()
        ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
        ctx.check_hostname = False
        ctx.verify_mode = ssl.CERT_NONE
        self.assertRaises(ValueError, ftplib.FTP_TLS, keyfile=CERTFILE,
                          context=ctx)
        self.assertRaises(ValueError, ftplib.FTP_TLS, certfile=CERTFILE,
                          context=ctx)
        self.assertRaises(ValueError, ftplib.FTP_TLS, certfile=CERTFILE,
                          keyfile=CERTFILE, context=ctx)

        self.client = ftplib.FTP_TLS(context=ctx, timeout=TIMEOUT)
        self.client.connect(self.server.host, self.server.port)
        self.assertNotIsInstance(self.client.sock, ssl.SSLSocket)
        self.client.auth()
        self.assertIs(self.client.sock.context, ctx)
        self.assertIsInstance(self.client.sock, ssl.SSLSocket)

        self.client.prot_p()
        with self.client.transfercmd('list') as sock:
            self.assertIs(sock.context, ctx)
            self.assertIsInstance(sock, ssl.SSLSocket) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:25,代碼來源:test_ftplib.py

示例7: __init__

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def __init__(self, host, username='', password=''):
        self._client = ftplib.FTP_TLS(timeout=10)
        self._client.connect(host)

        # enable TLS
        try:
            self._client.auth()
        except ftplib.error_perm:
            # TLS authentication not supported
            # fallback to a plain FTP client
            self._client.close()
            self._client = ftplib.FTP(timeout=10)
            self._client.connect(host)
        
        self._client.login(username, password)

        if hasattr(self._client, 'prot_p'):
            self._client.prot_p() 
開發者ID:PacktPublishing,項目名稱:Modern-Python-Standard-Library-Cookbook,代碼行數:20,代碼來源:networking_03.py

示例8: _ftp_connect

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def _ftp_connect(self):
        try:
            self.conn.voidcmd("NOOP")
            return True
        except:
            if self.tls:
                self.conn = ftplib.FTP_TLS()
            else:
                self.conn = ftplib.FTP()
            self.conn.connect(self.host, self.port, timeout=self.timeout)
            self.conn.login(self.username, self.password)
            if self.tls:
                self.conn.prot_p() 
開發者ID:d6t,項目名稱:d6tpipe,代碼行數:15,代碼來源:ftp.py

示例9: setUp

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def setUp(self):
        self.server = DummyTLS_FTPServer((HOST, 0))
        self.server.start()
        self.client = ftplib.FTP_TLS(timeout=10)
        self.client.connect(self.server.host, self.server.port)
        # enable TLS
        self.client.auth()
        self.client.prot_p() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_ftplib.py

示例10: test_check_hostname

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def test_check_hostname(self):
        self.client.quit()
        ctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
        ctx.verify_mode = ssl.CERT_REQUIRED
        ctx.check_hostname = True
        ctx.load_verify_locations(CAFILE)
        self.client = ftplib.FTP_TLS(context=ctx, timeout=TIMEOUT)

        # 127.0.0.1 doesn't match SAN
        self.client.connect(self.server.host, self.server.port)
        with self.assertRaises(ssl.CertificateError):
            self.client.auth()
        # exception quits connection

        self.client.connect(self.server.host, self.server.port)
        self.client.prot_p()
        with self.assertRaises(ssl.CertificateError):
            self.client.transfercmd("list").close()
        self.client.quit()

        self.client.connect("localhost", self.server.port)
        self.client.auth()
        self.client.quit()

        self.client.connect("localhost", self.server.port)
        self.client.prot_p()
        self.client.transfercmd("list").close() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:29,代碼來源:test_ftplib.py

示例11: login

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def login(self, *args, **kwargs):
            ftplib.FTP_TLS.login(self, *args, **kwargs)
            self.prot_p() 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:5,代碼來源:test_functional_ssl.py

示例12: setUp

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def setUp(self):
        self.server = FTPSServer()
        self.server.start()
        self.client = ftplib.FTP_TLS(timeout=TIMEOUT)
        self.client.connect(self.server.host, self.server.port) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:7,代碼來源:test_functional_ssl.py

示例13: setUp

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def setUp(self):
        self.server = DummyTLS_FTPServer((HOST, 0))
        self.server.start()
        self.client = ftplib.FTP_TLS(timeout=TIMEOUT)
        self.client.connect(self.server.host, self.server.port)
        # enable TLS
        self.client.auth()
        self.client.prot_p() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:10,代碼來源:test_ftplib.py

示例14: test_check_hostname

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def test_check_hostname(self):
        self.client.quit()
        ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        ctx.verify_mode = ssl.CERT_REQUIRED
        ctx.check_hostname = True
        ctx.load_verify_locations(CAFILE)
        self.client = ftplib.FTP_TLS(context=ctx, timeout=TIMEOUT)

        # 127.0.0.1 doesn't match SAN
        self.client.connect(self.server.host, self.server.port)
        with self.assertRaises(ssl.CertificateError):
            self.client.auth()
        # exception quits connection

        self.client.connect(self.server.host, self.server.port)
        self.client.prot_p()
        with self.assertRaises(ssl.CertificateError):
            with self.client.transfercmd("list") as sock:
                pass
        self.client.quit()

        self.client.connect("localhost", self.server.port)
        self.client.auth()
        self.client.quit()

        self.client.connect("localhost", self.server.port)
        self.client.prot_p()
        with self.client.transfercmd("list") as sock:
            pass 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:31,代碼來源:test_ftplib.py

示例15: get_file_ftps

# 需要導入模塊: import ftplib [as 別名]
# 或者: from ftplib import FTP_TLS [as 別名]
def get_file_ftps(host, path_to_file, ftps_configuration):
    """
        Copy an existing file from FTP via ftp://*host*/*path_to_file* link to home directory.
        The function return the full path to the file that has been downloaded.
    """
    # Construct FTP object and get the file on a server
    with ftplib.FTP_TLS(host, user = ftps_configuration["user"], passwd = ftps_configuration["psswd"]) as ftps:
        filename = re.findall("[^/]*$", path_to_file)[0]
        ftps.prot_p()
        with open(filename, "wb") as wf:
            ftps.retrbinary("RETR " + filename, wf.write)

    file_location = gc_write_dir + "/" + filename
    print("File " + path_to_file + " has got successfully.")
    return file_location 
開發者ID:OWOX,項目名稱:BigQuery-integrations,代碼行數:17,代碼來源:main.py


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