Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

ftplib returns EOFError

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


me at jonbowlas

May 19, 2008, 4:27 AM

Post #1 of 3 (265 views)
Permalink
ftplib returns EOFError

Hi All,

I've written a little method to connect to an ftpserver which works well,
however when I send a file using this ftp connection oddly I _sometimes_ get
returned an EOFError from ftplib.getline even though my file is actually
transferred.

Here's my script:

def uploadViaFtp(self, file, filename):
'''A method to upload a file via ftp'''
ftpserverloc = self.getItunesUftpServer()
ftpserverusername = self.getItunesUftpUser()
ftpserverpassword = self.getItunesUftpPsswd()
ftp = ftplib.FTP(ftpserverloc)
ftp.login(ftpserverusername, ftpserverpassword)
try:
ftp.storbinary("STOR " + filename, file, 1024)
finally:
file.close()
ftp.quit()


And here's the traceback:
Traceback (innermost last):
Module ZPublisher.Publish, line 114, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 40, in call_object
Module Products.FileSystemSite.FSPythonScript, line 108, in __call__
Module Shared.DC.Scripts.Bindings, line 311, in __call__
Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
Module Products.FileSystemSite.FSPythonScript, line 164, in _exec
Module None, line 28, in upload_submit
- <FSPythonScript at
/silva/service_views/UCLItunesUPodcast/edit/Asset/UCLItunesUTrack/upload_sub
mit>
- Line 28
Module Products.UCLItunesUPodcast.UCLItunesUService, line 138, in
uploadViaFtp
Module ftplib, line 523, in quit
Module ftplib, line 246, in voidcmd
Module ftplib, line 221, in voidresp
Module ftplib, line 207, in getresp
Module ftplib, line 193, in getmultiline
Module ftplib, line 183, in getline
EOFError


Any help in catching and ignoring this error would be greatly appreciated.

Regards

Jon

--
http://mail.python.org/mailman/listinfo/python-list


bockman at virgilio

May 19, 2008, 12:02 PM

Post #2 of 3 (254 views)
Permalink
Re: ftplib returns EOFError [In reply to]

On Mon, 19 May 2008 13:27:23 +0100, Jon Bowlas wrote:

> Hi All,
>
> I've written a little method to connect to an ftpserver which works well,
> however when I send a file using this ftp connection oddly I _sometimes_ get
> returned an EOFError from ftplib.getline even though my file is actually
> transferred.
>
> Here's my script:
>
> def uploadViaFtp(self, file, filename):
> '''A method to upload a file via ftp'''
> ftpserverloc = self.getItunesUftpServer()
> ftpserverusername = self.getItunesUftpUser()
> ftpserverpassword = self.getItunesUftpPsswd()
> ftp = ftplib.FTP(ftpserverloc)
> ftp.login(ftpserverusername, ftpserverpassword)
> try:
> ftp.storbinary("STOR " + filename, file, 1024)
> finally:
> file.close()
> ftp.quit()
>
>
> And here's the traceback:
> Traceback (innermost last):
> Module ZPublisher.Publish, line 114, in publish
> Module ZPublisher.mapply, line 88, in mapply
> Module ZPublisher.Publish, line 40, in call_object
> Module Products.FileSystemSite.FSPythonScript, line 108, in __call__
> Module Shared.DC.Scripts.Bindings, line 311, in __call__
> Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
> Module Products.FileSystemSite.FSPythonScript, line 164, in _exec
> Module None, line 28, in upload_submit
> - <FSPythonScript at
> /silva/service_views/UCLItunesUPodcast/edit/Asset/UCLItunesUTrack/upload_sub
> mit>
> - Line 28
> Module Products.UCLItunesUPodcast.UCLItunesUService, line 138, in
> uploadViaFtp
> Module ftplib, line 523, in quit
> Module ftplib, line 246, in voidcmd
> Module ftplib, line 221, in voidresp
> Module ftplib, line 207, in getresp
> Module ftplib, line 193, in getmultiline
> Module ftplib, line 183, in getline
> EOFError
>
>
> Any help in catching and ignoring this error would be greatly appreciated.
>
> Regards
>
> Jon

ftp.quit() attempts to send a quit command and wait for the response
before closing. Apparently, sometime the connection is already closed
(don't know why) and you get the exception.

I guess you could do something like this:

try:
ftp.quit()
except EOFError:
ftp.close()


Ciao
-----
FB
--
http://mail.python.org/mailman/listinfo/python-list


dorianmj at gmail

Aug 10, 2013, 4:43 AM

Post #3 of 3 (14 views)
Permalink
Re: ftplib returns EOFError [In reply to]

print "\t\tUploading file %s..." % newname
try:
self.ftp.storbinary("STOR %s" % newname, open(file))
except EOFError: # yep??
self.ftp.connect(self.ftpServ) # reconnecting
self.ftp.login(ftpUser, ftpPass)
self.ftp.storbinary("STOR %s" % newname, open(file))
print "\t\tFile %s uploaded" % newname

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.