3

I am trying to connect to FTP server to transfer a file. Here is my code;

import ftplib
ftp = ftplib.FTP()
host = host_name
port = 22
ftp.connect(host, port)
ftp.login(username, password)

But here is the error I got. Can anybody please help me? I would really appreciate your help.


EOFError Traceback (most recent call last)

<ipython-input-2-094fa8cc7c63> in <module>()
      3 host = host_name
      4 port = 22
----> 5 ftp.connect(host, port)
      6 ftp.login(username, password)

C:\Users\Ishwor.Bhatta\Anaconda3\lib\ftplib.py in connect(self, host, port, timeout, source_address)
    154         self.af = self.sock.family
    155         self.file = self.sock.makefile('r', encoding=self.encoding)
--> 156         self.welcome = self.getresp()
    157         return self.welcome
    158 

C:\Users\Ishwor.Bhatta\Anaconda3\lib\ftplib.py in getresp(self)
    233     # Raise various errors if the response indicates an error
    234     def getresp(self):
--> 235         resp = self.getmultiline()
    236         if self.debugging:
    237             print('*resp*', self.sanitize(resp))

C:\Users\Ishwor.Bhatta\Anaconda3\lib\ftplib.py in getmultiline(self)
    223             code = line[:3]
    224             while 1:
--> 225                 nextline = self.getline()
    226                 line = line + ('\n' + nextline)
    227                 if nextline[:3] == code and \

C:\Users\Ishwor.Bhatta\Anaconda3\lib\ftplib.py in getline(self)
    207             print('*get*', self.sanitize(line))
    208         if not line:
--> 209             raise EOFError
    210         if line[-2:] == CRLF:
    211             line = line[:-2]

EOFError: 
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Ishwor Bhatta
  • 139
  • 1
  • 3
  • 13

2 Answers2

4

As far as I understand from the exception documentation:

exception EOFError

Raised when the input() function hits an end-of-file condition (EOF) without reading any data. (N.B.: the io.IOBase.read() and io.IOBase.readline() methods return an empty string when they hit EOF.)

This means that the server is sending you an EOF, to tell you that connection has been terminated while you were expecting to read something instead.

Looking at the method's source code and the comment above it, it says:

# Raise EOFError if the connection is closed

Many reasons to cause the server to close the connection, among them:

Firewall setup, proxy, wrong port .. etc

Iron Fist
  • 10,739
  • 2
  • 18
  • 34
  • 1
    The question is [duplicate](http://stackoverflow.com/q/2019780/850848), so there's no point trying to answer it again. Let only with so vague answer. Rather vote for it to be closed. – Martin Prikryl Mar 23 '17 at 15:13
  • 1
    Very good answer! Now I understand what this error means. Moreover, I know that the problem is on server side rather on client side! – Lukasz Dynowski Jan 05 '18 at 08:32
3

I was able to solve the problem with following code;

import paramiko

transport = paramiko.Transport((host_name, 22))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)

Thanks everyone

aydow
  • 3,673
  • 2
  • 23
  • 40
Ishwor Bhatta
  • 139
  • 1
  • 3
  • 13