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 815309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:39:49+00:00 2026-05-15T01:39:49+00:00

EDIT: I got it working it just won’t download anything… So here is my

  • 0

EDIT: I got it working it just won’t download anything…

So here is my code simplified now:

notions_ftp = ftplib.FTP(ftp_host, ftp_user, ftp_passwd)
folder = "Leisure Arts - Images"
notions_ftp.cwd(folder)
image = open("015693PR-com.jpg","wb")
notions_ftp.retrlines("RETR 015693PR-com.jpg", image.write)
send_image = open("015693PR-com.jpg", 'r')

And Here is my output:

'250 "/Leisure Arts - Images": is current directory.'
'226 Transfer complete. 0 bytes in 0.00 sec. (0.000 Kb/s)'

Original Post:
OK So I have been messing with this all day long. I am fairly new to Python FTP. So I have searched through here and came up w/ this:

images = notions_ftp.nlst()
    for image_name in image_names:
        if found_url == False:
            try:
                for image in images:
                    ftp_image_name = "./%s" % image_name
                    if ftp_image_name == image:
                        found_url = True
                        image_name_we_want = image_name
            except:
                pass

    # We failed to find an image for this product, it will have to be done manually
    if found_url == False:
        log.info("Image ain't there baby -- SKU: %s" % sku)
        return False
    # Hey we found something! Open the image....
    notions_ftp.retrlines("RETR %s" % image_name_we_want, open(image_name_we_want, "rb"))
    1/0

So I have narrowed the error down to the line before I divide by zero. Here is the error:

Traceback (most recent call last):
  File "<console>", line 6, in <module>
  File "<console>", line 39, in insert_image
IOError: [Errno 2] No such file or directory: '411483CC-IT,IM.jpg'

So if you follow the code you will see that the image IS in the directory because image_name_we_want is set if found in that directory listing on the first line of my code. And I KNOW it’s there because I am looking at the FTP site myself and …it’s freakin there. So at some point during all of this I got the image to save locally, which is most desired, but I have long since forgot what I used to make it do that. Either way, why does it think that the image isn’t there when it clearly finds it in the listing.

OK so I took the suggestion and now I get:

14:01:18,057 ERROR [pylons-admin] Image to big or corrupt! Skipping Image for product sku: 411483
14:01:18,057 ERROR [pylons-admin] Image to big or corrupt! Skipping Image for product sku: 411483
Traceback (most recent call last):
  File "<console>", line 6, in <module>
  File "<console>", line 40, in insert_image
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ftplib.py", line 418, in retrlines
    callback(line)
TypeError: 'file' object is not callable
>>> 14:01:24,694 INFO  [pylons-admin] Script Done! Updated 0 Products w/ Images

So it got the first image, which I think really is corrupt, but then when it goes on to the next one to be processed it throws that error on the file object. So here is how I changed it and the rest of the code not put here in the first place:

# Hey we found something! Open the image....
    f = open(image_name_we_want, "wb")
    notions_ftp.retrlines("RETR %s" % image_name_we_want, f)
    send_image = open(image_name_we_want, 'r')

    # ...and send it for processing
    try:
        image_id = product_obj.set_image(send_image, 5, 1)
    except IOError, error:
        log.error("Image to big or corrupt! Skipping Image for product sku: %s" % sku)
        image_id = False
    else:
        if image_id == False:
            log.error("Could not Insert the image for product sku: %s" % sku)
            f.close()
            return False
        else:
            f.close()
            os.remove(image_name_we_want)
            return True
  • 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-05-15T01:39:50+00:00Added an answer on May 15, 2026 at 1:39 am

    You’re reading the file instead of writing it.

    So instead of open(image_name_we_want, "rb") use open(image_name_we_want, "wb")

    [edit]
    If you’re simply fetching from an ftp server than you could also try this:

    import urllib2
    fh = urllib2.urlopen('ftp://server/path/file.png')
    file('file.png', 'wb').write(fh.read())
    

    Also, for a fully working example read this: http://docs.python.org/library/ftplib.html

    You’re also missing the write after the open()

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

Sidebar

Related Questions

I'm working on a little experiment here. I've got a test file that I
I've got an app working semi-background stuff in the GUI thread. Another thread won't
Edit I got this working, I'm not sure if this is the right way
Edit : I've got an aspx file (default.aspx) that loads a flash file (index.swf),
Edit: I've got the solution and have described it a bit more at the
I've got to edit an XSLT stylesheet, but I'm flying blind because the XML
i got a page where the admin can edit some photos i pull from
Edit note: After a seemingly enourmous amount of bad feedback MS got from their
Edit 3 I went to the good'ol custom parsing approach as I got stuck
I've got a html.password helper control on an edit profile type screen. Is there

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.