本文整理汇总了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)
示例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
示例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()
示例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
示例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)
示例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)
示例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()
示例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()
示例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()
示例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()
示例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()
示例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)
示例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()
示例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
示例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