I am using pysftp to upload a local file that is processed remotely, then returned to the SFTP, where I can download it. At the moment, I cannot get the code to recognize that the processed remote file has been uploaded. The code just waits forever, despite the remotely processed file successfully being uploaded.
While the code is running, if I refresh the connection on a service such as FileZilla, the code instantly recognizes the file is in and works perfectly. However, I need it to work without manually refreshing on FileZilla. I am not sure why the code cannot recognize itself that the file has been uploaded and is ready to be downloaded.
I've already tried disconnecting then re-connecting to the SFTP using a while statement, which was not successful.
import pysftp
import stat
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
srv = pysftp.Connection(host="host", username="username", password="passowrd", cnopts=cnopts)
print("Connection Made!")
# Put File In
srv.chdir(r'/path_to_remote_directory')
srv.put(r'C:\Path_to_local_file.csv')
print("File Uploaded")
while not srv.isfile(r'/Path_to_newly_uploaded_remote_file.csv'):
time.sleep(3)
print("Still Waiting")
if srv.isfile(r'/Path_to_newly_uploaded_remote_file.csv'):
print("File is Ready!")
srv.get('/Path_to_newly_uploaded_remote_file.csv', r'C:\Local_path_save_to/file.csv')
# Closes the connection
srv.close()