Howardyan
Howardyan

Reputation: 657

can paramiko has the function to implememt uploading continue from the point from last interruption

I need implement a uploading function which can continue from the point from last interruption via sftp.

I'm trying paramiko. but I cannot fond any example about this. Can anybody give me some advices?

Best regards

Upvotes: 0

Views: 52

Answers (2)

Howardyan
Howardyan

Reputation: 657

base on whjm's advice, I wrote following code, it works. wish can help more people:

if filename in file_list:
    stat = sftp.stat(remot_dir + filename)
    f_local = open(local_dir + filename)
    f_local.seek(stat.st_size)
    f_remote = sftp.open(remot_dir + filename, "a")
    tmp_buffer = f_local.read(100000)
    while tmp_buffer:
        f_remote.write(tmp_buffer)
        tmp_buffer = f_local.read(100000)
    f_remote.close()
    f_local.close()
else:
    f_local = open(local_dir + filename)
    f_remote = sftp.open(remot_dir + filename, "w")
    tmp_buffer = f_local.read(100000)
    while tmp_buffer:
        f_remote.write(tmp_buffer)
        tmp_buffer = f_local.read(100000)
    f_remote.close()
    f_local.close()

Upvotes: 0

pynexj
pynexj

Reputation: 20698

SFTP.open(mode='a') opens a file in appending mode. So first you can call SFTP.stat() to get the current size of the file (on remote side) and then open(mode='a') it and append new data to it.

Upvotes: 1

Related Questions