1

I am getting the below error when running the Python code:

sftp.put(local_path, remote_path, callback=track_progress, confirm=True)

But if I make confirm=False then this error doesn't come. Definition of track_progress is as follows:

def track_progress(bytes_transferred, bytes_total):
    total_percent = 100
    transferred_percent = (bytes_transferred * total_percent) / bytes_total
    result_str = f"Filename: {file}, File Size={str(bytes_total)}b |-->
                 " f" Transfer Details ={str(transferred_percent)}% " \ f"({str(bytes_transferred)}b)Transferred"
    #self.logger.info(result_str)
    print(result_str)

Can anyone please help me understand the issue here.

Traceback (most recent call last):
  File "D:/Users/prpandey/PycharmProjects/PMPPractise/Transport.py", line 59, in <module>
    sftp.put(local_path, remote_path, callback=track_progress, confirm=True)
  File "D:\Users\prpandey\PycharmProjects\PMPPractise\venv\lib\site-packages\paramiko\sftp_client.py", line 759, in put
    return self.putfo(fl, remotepath, file_size, callback, confirm)
  File "D:\Users\prpandey\PycharmProjects\PMPPractise\venv\lib\site-packages\paramiko\sftp_client.py", line 720, in putfo
    s = self.stat(remotepath)
  File "D:\Users\prpandey\PycharmProjects\PMPPractise\venv\lib\site-packages\paramiko\sftp_client.py", line 495, in stat
    raise SFTPError("Expected attributes")
paramiko.sftp.SFTPError: Expected attributes

Paramiko log file:

enter image description here


As suggested, I have tried:

sftp.put(local_path, remote_path, callback=track_progress, confirm=False)
t, msg = sftp._request(CMD_STAT, remote_path)

The t is 101.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

1 Answers1

0

When you set confirm=True, the SFTPClient.put asks the server for a size of the just uploaded file. It does that to verify that the file size matches the size of the source local file. See also Paramiko put method throws "[Errno 2] File not found" if SFTP server has trigger to automatically move file upon upload.

The request for size uses SFTP "STAT" message, to which the server should either return "ATTRS" message (file attributes) or an "STATUS" message (101) with an error. Your server seems to return "STATUS" message with "OK" status (my guess based on the data from you and Paramiko source code). The "OK" is an invalid response to the "STAT" request. Paramiko does not expect such nonsense response, so it reports a bit unclear error. But ultimately it's a bug of the server. All you can do is to disable the verification by setting confirm=False.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992