[Tutor] FTP Upload
Alan Gauld
alan.gauld at yahoo.co.uk
Tue Jul 14 14:57:35 EDT 2020
On 14/07/2020 19:15, John Weller wrote:
> Hi
>
> I have some graphs created with matplotlib which I need to upload to a web server. I am using the command:
>
> filename = 'mygraph.png'
> ftp.storbinary("STOR " + filename, open(filename, "rb"))
>
> When I try to look at the graphs on the website they don't display and if I then download them to my PC using FileZilla and try to open them they are corrupt and show as Invalid Image. If however I upload them manually using FileZilla they display correctly on the website. I am obviously doing something wrong 😊 Advice please.
I don't see anything obviously wrong.
Suggestions:
1) implement the callback and use it to display progress,
just to check that the number of blocks is what you'd expect
for the filesize
2) pass the file object explicitly:
def callback(block):
....
print(....)
cmd = "STOR %s" % filename
fd = open(...)
if fd:
ftp.storbinary((cmd, fd, callback)
fd.close()
That shouldn't change anything, but my long standing approach to
anything involving files, especially binary ones, is to take
full control of opening and closing!
Othewise I don't know what's up.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list