本文整理汇总了Python中ftplib.FTP_TLS.pwd方法的典型用法代码示例。如果您正苦于以下问题:Python FTP_TLS.pwd方法的具体用法?Python FTP_TLS.pwd怎么用?Python FTP_TLS.pwd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ftplib.FTP_TLS
的用法示例。
在下文中一共展示了FTP_TLS.pwd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import pwd [as 别名]
def connect(self):
#初始化 FTP 链接
if self.ftp_ssl:
ftp = FTPS()
else:
ftp = FTP()
print('-'*20+self.ftp_name+'-'*20)
print('connect '+('ftps' if self.ftp_ssl else 'ftp')+'://'+self.ftp_host+':'+self.ftp_port)
try:
ftp.connect(self.ftp_host,self.ftp_port)
except Exception as e:
print (e)
print ('connect ftp server failed')
sys.exit()
try:
ftp.login(self.ftp_user,self.ftp_passwd)
print ('login ok')
except Exception as e:#可能服务器不支持ssl,或者用户名密码不正确
print (e)
print ('Username or password are not correct')
sys.exit()
if self.ftp_ssl:
try:
ftp.prot_p()
except Exception as e:
print (e)
print ('Make sure the SSL is on ;')
print(ftp.getwelcome())
ftp.cwd(self.ftp_webroot)
print('current path: '+ftp.pwd())
self.ftp=ftp
示例2: FTPClient
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import pwd [as 别名]
#.........这里部分代码省略.........
'htk_on_error', 'error: {0}'.format(ex), self._mh.fromhere())
return None
def change_dir(self, path):
"""Method changes remote working directory
Args:
path (str): new remote path
Returns:
bool: result
Raises:
event: ftp_before_change_dir
"""
try:
self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
'htk_ftp_change_dir', path), self._mh.fromhere())
if (not self._is_connected):
self._mh.demsg('htk_on_warning', self._mh._trn.msg(
'htk_ftp_not_connected'), self._mh.fromhere())
return False
ev = event.Event('ftp_before_change_dir', path)
if (self._mh.fire_event(ev) > 0):
path = ev.argv(0)
if (ev.will_run_default()):
self._client.cwd(path)
self._path = self._client.pwd()
self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
'htk_ftp_cur_dir', self._path), self._mh.fromhere())
return True
except all_errors as ex:
self._mh.demsg(
'htk_on_error', 'error: {0}'.format(ex), self._mh.fromhere())
return False
def download_file(self, remote_path, local_path=None):
"""Method downloads file from server
Args:
remote_path (str): remote path
local_path (str): local path, default ./filename
Returns:
bool: result
Raises:
event: ftp_before_download_file
event: ftp_after_download_file
"""
try:
self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
'htk_ftp_downloading_file', remote_path), self._mh.fromhere())
if (not self._is_connected):
示例3: FTP_TLS
# 需要导入模块: from ftplib import FTP_TLS [as 别名]
# 或者: from ftplib.FTP_TLS import pwd [as 别名]
secret = '123456'
host = '192.168.1.113'
try:
#instantiate FTPS
#ftps = FTP_TLS(host,user,secret)
ftps = FTP_TLS(host)
# TODO check why the next line not work
#See http://stackoverflow.com/questions/10207628/python-module-ftplib-ftp-tls-error-530
#Try TLS Lite or M2Crypto both are FTP/TLS client and server.
#ftps.login(user,secret)
ftps.sendcmd('USER ' + user)
ftps.sendcmd('PASS ' + secret)
print(ftps.getwelcome())
print('CURRENT WORKING DIRECTORY IS:',ftps.pwd())
#Enable data encryption
# TODO solve the encryption problem
#ftps.prot_p()
#define default DIR
d = 'feeds'
#Change to default DIR
ftps.cwd(d)
#Build list of files on servers
l = ftps.nlst()
l.sort()
for i in l:
print(i)
#Assign last element to var
litem = len(l)-1
print("MOST RECENT FILE ON SERVER IS; ",l[litem])