Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8062837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:48:38+00:00 2026-06-05T10:48:38+00:00

I have a script that connects to server and makes a local copy of

  • 0

I have a script that connects to server and makes a local copy of the whole directory.
EOFerror occurs after exactly 50 files of any choice have been downloaded.

Can anyone please tell me, what is wrong with the script?

ERROR:

Traceback (most recent call last):
  File "ftp.py", line 37, in <module>
    ftp_walk(ftp)
  File "ftp.py", line 17, in ftp_walk
    currdir = ftp.pwd()[1:]
  File "/usr/lib/python2.7/ftplib.py", line 574, in pwd
    resp = self.sendcmd('PWD')
  File "/usr/lib/python2.7/ftplib.py", line 244, in sendcmd
    return self.getresp()
  File "/usr/lib/python2.7/ftplib.py", line 210, in getresp
    resp = self.getmultiline()
  File "/usr/lib/python2.7/ftplib.py", line 196, in getmultiline
    line = self.getline()
  File "/usr/lib/python2.7/ftplib.py", line 186, in getline
    if not line: raise EOFError
EOFError

SCRIPT:

#!/usr/bin/python

import ftplib
import sys
import os
import datetime

def ftp_walk(ftp):    
    dirs = ftp.nlst()
    for item in (path for path in dirs if path not in ('.', '..')):
        try:
            ftp.cwd(item)
            print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")+' DIR: ', ftp.pwd()
            ftp_walk(ftp)
            ftp.cwd('..')
        except Exception, e:
            currdir = ftp.pwd()[1:]
            if not os.path.exists(currdir): os.makedirs(currdir)
            try:
                with open(currdir+"/"+item, 'wb') as f:

                    def callback(data):
                        f.write(data)

                    ftp.retrbinary('RETR %s' % item, callback)
                    f.close()
                    print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")+' RETR: '+ currdir+"/"+item
            except Exception, e:
                print e


ftp = ftplib.FTP("hhhhhhhhhhhhhh")
ftp.login("aaaaaaaa", "bbbbbbbbbbb")
ftp.sendcmd("TYPE I") #binary mode
ftp.set_pasv(True) # Trying Passive mode
ftp.cwd("public_html/eeeeeeee/rrrrrrrr/images")
ftp_walk(ftp)
ftp.quit()

Edit:
After manual update of ftplib for python 2.7:

Traceback (most recent call last):
  File "ftp.py", line 29, in <module>
    ftp = ftplib.FTP("something.com")
  File "/usr/lib/python2.7/ftplib.py", line 114, in __init__
    self.connect(host)
  File "/usr/lib/python2.7/ftplib.py", line 150, in connect
    self.file = self.sock.makefile('r', encoding=self.encoding)
TypeError: makefile() got an unexpected keyword argument 'encoding'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:48:40+00:00Added an answer on June 5, 2026 at 10:48 am

    I have tried your script and it works without any problems. I just pulled 233 images from my server using it. Try setting the current dir to ftp.cwd("./public_html/eeeeeeee/rrrrrrrr/images") and see what happens…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that connects to SQL Server 2005 default instance. But I'm
I have a script that connects to multiple databases (Oracle, MySQL and MSSQL), each
Ok so I have a script that connects to a mssql db and i
I have a PHP script that connects to an API and grabs around 200
In the office here we have a startup script that runs on the server
I have an ajax request that requests a php script that connects to my
I've got this script, that uploads some files, connects via ssh and does some
I have a c# script that does 2 things This script connects a my
I have a script that creates a random string and I want to turn
We have a script that saves some rows in a table and one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.