加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python FTP到iPad

发布时间:2020-12-16 22:18:39 所属栏目:Python 来源:网络整理
导读:我在Windows 7上. 我无法使用简单的Python脚本连接到我的iPad: HOST = '192.168.1.122'try: f = ftplib.FTP(HOST)except (socket.error,socket.gaierror),e: MessageBox.Show('ERROR: cannot reach "%s"' % HOST) return try: f.connect(HOST,2121) f.login

我在Windows 7上.

我无法使用简单的Python脚本连接到我的iPad:

HOST = '192.168.1.122'
try:
    f = ftplib.FTP(HOST)
except (socket.error,socket.gaierror),e:    
    MessageBox.Show('ERROR: cannot reach "%s"' % HOST)
    return          
try:
    f.connect(HOST,2121)
    f.login()
except ftplib.error_perm:
    MessageBox.Show('ERROR: cannot login anonymously')
    f.quit()
    return

我遇到的错误是“getaddrinfo返回一个空列表”和“无法到达…”消息…无法解决它…

我尝试使用iPad上的几个程序进行FTP而没有成功.如果我通过DOS框FTP或使用FTP软件,它的工作原理.我在我的电脑上尝试了另一台FTP服务器,但它确实有效.

我被迫使用端口2121,所以不能改变它.

任何线索或经验?

最佳答案
您应该在任何事情之前阅读文档:

class ftplib.FTP([host[,user[,
passwd[,acct[,timeout]]]]]) Return a
new instance of the FTP class. When
host is given,the method call
connect(host) is made. When user is
given,additionally the method call
login(user,passwd,acct) is made
(where passwd and acct default to the
empty string when not given). The
optional timeout parameter specifies a
timeout in seconds for blocking
operations like the connection attempt
(if is not specified,the global
default timeout setting will be used).

因此,如果你执行f = ftplib.FTP(HOST)它会失败,因为它将尝试连接到标准端口(21)而不是2121.
你应该得到一个ftplib的实例,然后使用f.connect(HOST,2121).

http://docs.python.org/library/ftplib.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读