0

I am trying to upload a CSV file of 2mb on my FTP server. The internet is slow, so the program takes 20 seconds to write the complete file.

But the code is writing file line by line, I think. Every 1 second, the CSV file increases till it is fully uploaded.

I want the code to write the file only when it's 100% uploaded. How can I do that?

import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
s=pysftp.Connection(host="xx.xx.xx.xx", username="root", password='abcpassword',cnopts=cnopts)
s.put(local_path, remote_path)

How to change s.put() function, so it writes full only after it's 100% uploaded. Till that time, keep the file in memory/buffer something

rahul sharma
  • 109
  • 1
  • 8
  • 2
    Can't be done. Actual writing of the file on the remote server is done by the server and no change on the client side can affect it. – Błotosmętek Feb 28 '20 at 15:32
  • One script update the CSV file every minute. Another script read CSV file every 2-3 second. So I want the 2nd script to read old CSV till the new CSV is 100% written – rahul sharma Feb 28 '20 at 15:41
  • Okay.I found how to solve my problem. I need to create two files "file_original.csv" and "file_old.csv". The second file will be 100% copied and the script will read this – rahul sharma Feb 28 '20 at 16:03
  • But how can I copy the uploaded file and rename it to "file_old.csv", as soon as it is done? I did not find any function for this in Pysftp https://pysftp.readthedocs.io/en/release_0.2.8/cookbook.html – rahul sharma Feb 28 '20 at 16:04

0 Answers0