[Tutor] FTP Upload
John Weller
john at johnweller.co.uk
Thu Jul 16 09:16:42 EDT 2020
>
> On 15/07/2020 17:09, John Weller wrote:
> >> 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
> >>
> > I'm struggling to understand callback. As I know the problem, ie bytes being
> dropped,> would callback be of any benefit? If so, how would I implement it.
>
> >> def callback(block):
> >> ....
> >> print(....)
>
> At the simplest level just store how many times callback gets called.
> (It should be once every block) so you can see if the expected number of blocks are
> being sent. In particular whether the final (partial) block is being sent...
>
> You could do fancier stuff like check the size of block each time and print that:
>
> count = 0
>
> def callback(black):
> global count
> count += 1
> print("Block %d sent with size %d" % (count, len(block))
>
>
> cmd = "STOR %s" % "my_graph.png"
> fd = open("my_graph.png", "rb")
> if fd: # I assume open() returns False if it can't open the file
> ftp.storbinary(cmd, fd, callback)fd.close() print ("A total of %d blocks sent"
> % count)
>
> Assuming your files are not massive. If they are then simply limit the prints to every
> 10th or if len(block) != blocksize
>
> Note, none of that is tested, just based on reading the docs on callback!... :-)
Hi Alan,
Thanks as always for your help. The problem seems to have gone away so was obviously caused by a noisy internet connection; I immediately jumped to the conclusion that it was something I had done wrong 😊
I included the callback procedure in a test program I was running and it caused syntax errors in the following lines that I couldn't trace so in the end, as it is now working, I left it out.
Regards
John
John Weller
01380 723235
07976 393631
More information about the Tutor
mailing list