LonelySoul
LonelySoul

Reputation: 1232

ftplib error while execution

While accessing the remote server through FTP I am getting following error. Not sure whats the problem of it so I can solve. Any lead will be helpful.

Code:

import ftplib
from ftplib import FTP
ftp = ftplib.FTP("server_name")

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.6/ftplib.py", line 116, in __init__
    self.connect(host)
  File "/usr/lib64/python2.6/ftplib.py", line 131, in connect
    self.sock = socket.create_connection((self.host, self.port), self.timeout)
  File "/usr/lib64/python2.6/socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known

Upvotes: 2

Views: 2107

Answers (2)

randingo
randingo

Reputation: 61

(I don't have enough reputation to just leave a comment for @LonelySoul, and anyone else.)

You'll encounter the Name or service not known exception if "server_name" includes the protocol. Simply removing ftp:// resolved the issue for me.

Upvotes: 5

abarnert
abarnert

Reputation: 366103

The error is telling you that it can't find the host named server_name. So, that's what you need to debug.

If you ping server_name in your terminal/DOS prompt, does it work, or give you an error like cannot resolve server_name? What if you ftp server_name in the terminal?

If everything works in the terminal, and you don't have a silly typo in your code, your next step is to debug why Python is getting it wrong. Write some code that tries to call getaddrinfo explicitly and see what happens. Try socket.connect on a normal IPv4 socket to see if it works. (If so, the problem is probably something to do with IPv6.) And so on.

More likely, it will fail in the terminal as well. In that case, either you've got the wrong name for the server, or you've got something wrong with your network or system setup; either way, it's not a programming problem, and StackOverflow won't be able to help you further.

Upvotes: 1

Related Questions