0

So here is my code

import ftplib

s = ftplib.FTP("Host", "Username", "Password")
s.cwd("public_html/test")
image = open("test.jpg", "rb")
s.storbinary('STOR test.jpg', image) 
image.close()
s.quit()

I'm just getting a corrupted image when I check it out... I'm to the point where I'll base64 the image and upload that...

If anyone can help please let me know what I'm doing wrong

TheBestJohn
  • 597
  • 1
  • 6
  • 14
  • 2
    It might help if you can do a binary-diff and describe _how_ the image is corrupted. Is it zero bytes? Is it correct to a point, but the remainder is missing? Is it mostly correct but a few bytes are wrong? Are the sizes the same or similar? – Jon-Eric Nov 27 '12 at 22:20
  • It looks like they are 0b it seems to make the file but not do any uploading – TheBestJohn Nov 27 '12 at 23:35

1 Answers1

3

I'm not entirely sure what was wrong but this is what finally worked for me

import ftplib
import traceback

n="name of upload"
ftp = ftplib.FTP()
ftp.connect("website.com", "21")
print ftp.getwelcome()
try:
    try:
    ftp.login("user", "password")
    ftp.cwd("public_html/test")
    f = open("test.JPG", "rb")
    name= str(n)+".jpg"
    ftp.storbinary('STOR ' + name, f)
    f.close()
finally:
    ftp.quit()
except:
    traceback.print_exc()

Hope this helps anyone else in the same predicament

TheBestJohn
  • 597
  • 1
  • 6
  • 14