使用FTP的FTP工具模块时出错
class FTPHost(object):
"""Represent a connection to a remote host.
A remote host has a working directory, and an ftplib object connected.
"""
def __init__(self, ftp_obj):
"""Initialize with a ftplib.FTP instance (or an instance of a
subclass). Use the classmethod connect to create an actual ftplib
connection and get an FTPHost instance.
"""
self.ftp_obj = ftp_obj
def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self.ftp_obj)
def __str__(self):
return "<%s at %s:%d (%s)>" % (self.__class__.__name__,
self.ftp_obj.host, self.ftp_obj.port, self.ftp_obj)
@classmethod
def connect(cls, host, port=21, user=None, password=None, account=None,
ftp_client=ftplib.FTP, debuglevel=0, timeout=None):
"""Connect to host, using port. If user is given, login with given
user, password and account. The two latter can be None, in which case
ftplib will set the password to 'anonymous@'. You can choose which
class to instance by means of ftp_client.
"""
ftp_obj = ftp_client()
ftp_obj.set_debuglevel(debuglevel)
if timeout is not None:
old_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(float(timeout))
ftp_obj.connect(host, port)
socket.setdefaulttimeout(old_timeout)
else:
ftp_obj.connect(host, port)
# And log in.
if user:
ftp_obj.login(user, password, account)
return cls(ftp_obj)
当调用FTPhost.connect(服务器,名称,传递)时,我收到错误FTPhost未定义。 Python的新手,并尝试查看代码,但无济于事。
答案 0 :(得分:0)
我对ftptool也很新鲜,我遇到了同样的问题。 这是我的方式。
来自ftptool导入FTPHost