Python Forum
ftplib and pyftpdlib : REST (restart) command not working as expected when uploading
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ftplib and pyftpdlib : REST (restart) command not working as expected when uploading
#1
I've set up a simple FTP server with pyftpdlib and a client with ftplib. When i let the client script run, it uploads the file correctly as expected.

pyftpdlib Server code:
import logging
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer

authorizer = DummyAuthorizer()
authorizer.add_user("test","123","C:\\Users\\Usr\\Desktop\\server_data","elradfmwM")
handler = FTPHandler
handler.authorizer = authorizer
logging.basicConfig(level=logging.DEBUG)
connection = ("localhost", 8080)
ftpd = FTPServer(connection, handler)
ftpd.serve_forever()
ftplib Client code #1:
import ftplib

ftp = ftplib.FTP()
ftp.connect("localhost",8080)
ftp.login("test","123")

block_size = 128
c_dir = "C:\\Users\\Usr\\Desktop\\client_data"
filename = "test.pdf" # ~ 30Mb

ftp.dir()
myfile = open(c_dir + "\\" + filename , "rb")

ftp.storbinary("STOR " + filename, myfile, blocksize=block_size)

ftp.dir()
ftp.close()
Now i wanted to test the REST (restart upload/download from a specific position) functionality. So i interrupted the client code while still uploading (simply by closing my command prompt while it was uploading). Next, while the server was still running, i ran the following client code in an attempt to resume the upload from the interrupted position:


ftplib Client code #2:
import ftplib

ftp = ftplib.FTP()
ftp.connect("localhost",8080)
ftp.login("test","123")

block_size = 128
c_dir = "C:\\Users\\Usr\\Desktop\\client_data"
filename = "test.pdf" # ~ 30Mb

ftp.dir()
myfile = open(c_dir + "\\" + filename , "rb")

ftp.voidcmd('TYPE I')
rest_pos = ftp.size(filename)
print(rest_pos)
ftp.storbinary("STOR " + filename, myfile, blocksize=block_size, rest=rest_pos)

ftp.dir()
ftp.close()
When i run client code #2 it does upload but it seems it doesn't start at the correct position.

The file size is ca. 30 Mb

Client code #1 uploads correctly (ca 30Mb)

Client code #2 uploads but the file is larger and corrupted (ca 35Mb)

I've compared the output of rest_pos with the file size under Windows after interrupting and they do match. So the position rest i'm passing to ftp.storbinary is the same as under Windows.



I'm fairly new to python and ftp and cant figure out what the issue is. Googled, but couldn't find anything similar.

Any tips/hints would be appreciated :)
Reply


Messages In This Thread
ftplib and pyftpdlib : REST (restart) command not working as expected when uploading - by darellon - Mar-05-2017, 04:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to restart another PC on the local network? Kundan 1 2,108 Sep-21-2019, 11:31 AM
Last Post: ThomasL
  ftplib os.listdir function peterkl 1 4,576 Jun-07-2019, 08:21 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020