将文件上传到FTP服务器时出错 [英] Error uploading a file to a ftp server
问题描述
我有一个将文本文件发送到FTP服务器的程序。代码是:
def sendBug():
session = ftplib.FTP('ftp: (bugreport.txt,r)
session.storlines(STOR bugreport.txt,bug文件)
bugfile.close()
session.quit()
然而,
Traceback(最近一次调用最后一次):
File C:\Python27\lib\lib-tk\Tkinter.py,行1470,在__call__
中返回self.func(* args)
文件C:\Users\\ \\ Nitro \ Desktop \py2exe stuff\school firewall ui.py,第46行,在getnews
ftp = ftplib.FTP(服务器)
文件C:\Python27\lib\\ \\ftplib.py,第120行,在__init__
self.connect(主机)
文件C:\Python27\lib\ftplib.py,行135,连接
self.sock = socket.create_connection((self.host,self.port),self.timeout)
文件C:\Python27\\ lib_socket.py,第553行,在create_connection
中,用于getaddrinfo(host,port,0,SOCK_STREAM)中的res:
gaierror:[Errno 11004] getaddrinfo失败
有什么办法解决这个问题?我用IIS托管一个ftp服务器。学校防火墙用户界面是我的程序。
对于第一个服务器行,不需要ftp ://
Basiclly gaierror:[Errno 11004] getaddrinfo失败
ftp模块不能理解你给他的'ftp://xxxx.xxxx.xxxx.xxxx'
地址 - 主机名。
来自文档的
gaierror
:
这个地址相关的错误引发了这个异常, getaddrinfo()和getnameinfo()。伴随的值是表示由库调用返回的错误的一对(错误,字符串)。字符串表示由gai_strerror()C函数返回的错误描述。错误值将与此模块中定义的其中一个EAI_ *常量匹配。
您正在传递 ftplib.FTP()
带有主机,用户名和密码(用户名和密码都是空格)
如果它应该是匿名的,只需使用:
ftp = ftplib.FTP('you address')
ftp.login()
如果它仍然不起作用,请尝试ping您的地址或尝试连接一些已知的FTP来低估问题出在哪里。
你也可以试试这个 link 非常有用
有关python FTP的更多信息,请尝试 docs
I have a program which sends a text file to a ftp server. The code is:
def sendBug():
session = ftplib.FTP('ftp://xxxx.xxxx.xxxx.xxxx', " ", " ")
bugfile = open(bugreport.txt, "r")
session.storlines("STOR bugreport.txt", bugfile)
bugfile.close()
session.quit()
However, when I run that script, I'm getting something like this:
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
File "C:\Users\Nitro\Desktop\py2exe stuff\school firewall ui.py", line 46, in getnews
ftp= ftplib.FTP(server)
File "C:\Python27\lib\ftplib.py", line 120, in __init__
self.connect(host)
File "C:\Python27\lib\ftplib.py", line 135, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout)
File "C:\Python27\lib\socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno 11004] getaddrinfo failed
any way to fix this? Im hosting a ftp server with IIS. And school firewall ui is my program.
for first Server line doen't need the "ftp://"
Basiclly gaierror: [Errno 11004] getaddrinfo failed
means that the ftp module can't understand the 'ftp://xxxx.xxxx.xxxx.xxxx'
address you gave him - host name.
gaierror
from Docs:
This exception is raised for address-related errors, for getaddrinfo() and getnameinfo(). The accompanying value is a pair (error, string) representing an error returned by a library call. string represents the description of error, as returned by the gai_strerror() C function. The error value will match one of the EAI_* constants defined in this module.
You are passing ftplib.FTP()
with host, username and password (both user and password are space at your case)
if it's supposed to be anonymous just use:
ftp = ftplib.FTP('you address')
ftp.login()
If it still doesn't work try to ping your address or try to connect some known FTP to understated where is the problem.
You can also try this link it's very useful
For more info about python FTP try the docs
这篇关于将文件上传到FTP服务器时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!