ftp到主机名如何失败,即使DNS提供valide ip addr和ftp到addr成功?


0

这怎么可能?

NodeX# ping ftp.company.com
PING ftp.company.com (xx.yy.8.11) 56(84) bytes of data.
64 bytes from ftp.company.com (xx.yy.8.11): icmp_seq=1 ttl=127 time=0.657 ms
...
^C
NodeX# /usr/bin/myftp.py -fftp.company.com -uuser -ppasssword 
Transferring myftp.tgz to ftp.company.com:Incoming/
*** ftp login failed: [Errno -5] No address associated with hostname
Operation failed, exit code=3

如果我这样做,它的工作原理:

NodeX# /usr/bin/myftp.py -fxx.yy.8.11 -uuser -ppassword 
Transferring myftp.tgz to ftp.company.com:Incoming/
Operation completed successfully

此外,如果我在/ etc / hosts中创建一个条目,那么它使用该名称。是什么赋予了?

挖掘节目:

NodeX# dig ftp.company.com ANY

; <<>> DiG 9.5.0-P2 <<>> ftp.company.com ANY
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21125
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;ftp.company.com. IN      ANY

;; ANSWER SECTION:
ftp.company.com. 28800 IN A       xx.yy.8.11

;; Query time: 1 msec
;; SERVER: xx.zz.8.34#53(xx.zz.8.34)
;; WHEN: Thu Oct 11 14:53:00 2012
;; MSG SIZE  rcvd: 63

resolv.conf显示2个名称服务器,一个dig @each返回IP。

Python 2.6代码如下所示:

    try:
        print("Preparing ftplib.FTP for " + ftpHost)
        ftp = ftplib.FTP()
    except Exception, e:
        print("*** ftp prep failed: %s" % e.__str__())
        return 3
    end
    try:
        print("Connecting to '" + ftpHost + "'")
        ftp.connect(ftpHost, ftpPort)
    except Exception, e:
        print("*** ftp connection failed: %s" % e.__str__())
        return 4
    end

输出是:

Preparing ftplib.FTP for ftp.company.com
Connecting to 'ftp.company.com'
*** ftp connection failed: [Errno -5] No address associated with hostname
Operation failed, exit code=4

而:

Node2414332# ping ftp.company.com
PING ftp.company.com (xx.yy.8.11) 56(84) bytes of data.
64 bytes from ftp.company.com (xx.yy.8.11): icmp_seq=1 ttl=127 time=0.804 ms

解决了:

虽然我们的python的createconnection()在给定主机名(参见下文)时在getaddrinfo()中失败,但它使用地址。方便地,gethostbyname()有效,所以我们有简单的修复:createconnection(gethostbyname(hostname))。 Weerd。


2
这可能是一个更好的问题 serverfault.com

1
“挖掘ftp.company.com ANY”的输出是什么样的?
David K. Hess

可以通过resolv.conf中的所有名称服务器解析该主机名吗? (我假设你根据你的提示和路径使用Linux)机器双归属?
tMC

2
你有没有机会在主机名中加一个短划线“ - ”,导致解析行参数以解释它们错了?

@David,我用挖掘输出扩展了这个问题 - 感谢你有一个去:)
DJC
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.