0

I can't understand why I am not able to PUT my file correctly. The file exists (I am certain of it) I fear it may be a path problem but I am not sure: the file is named (and I cannot change it) some thing like ABC.csv.TEMP.inc

Furthermore I am not sure if the library is "happy" with windows paths, ie: "path\to\location". I have tried also using the "path/to/location" format but the result does not change.

my class below

import pysftp

class SFTPTalker:

    def __init__(self):
        self.myHostname = "HOST"
        self.myUsername = "USER"
        self.myPassword = "PASS"
    
    def transfer(self, filepath) :
        returnStatus = False
        errorString = ''

        try:
            cnopts = pysftp.CnOpts()
            cnopts.hostkeys = None
            with pysftp.Connection(self.myHostname, username = self.myUsername, password = self.myPassword, private_key = ".ppk", cnopts = cnopts) as sftp:
                sftp.put(filepath)
            sftp.close()
            returnStatus = True

        except Exception as e:
            print(e)
            errorString = str(e)
            returnStatus = False
        
        return returnStatus, errorString

the exception raised is [Errno 2] No such file and I am using pysftp==0.2.9

Thanks for the help!

EDIT: Complete stack trace follows as requested (omitted organization's paths)

Traceback (most recent call last):
  File "path\to\script\guiWrapper.py", line 161, in Execute
    ftpTransferResult, errorString = transfer.transfer(fileToTransfer)
  File "path\to\venv\lib\site-packages\RECAIM\SFTP.py", line 23, in transfer
    sftp.put(file)
  File "path\to\venv\lib\site-packages\pysftp\__init__.py", line 363, in put
    sftpattrs = self._sftp.put(localpath, remotepath, callback=callback,
  File "path\to\venv\lib\site-packages\paramiko\sftp_client.py", line 759, in put
    return self.putfo(fl, remotepath, file_size, callback, confirm)
  File "path\to\venv\lib\site-packages\paramiko\sftp_client.py", line 720, in putfo
    s = self.stat(remotepath)
  File "path\to\venv\lib\site-packages\paramiko\sftp_client.py", line 493, in stat
    t, msg = self._request(CMD_STAT, path)
  File "path\to\venv\lib\site-packages\paramiko\sftp_client.py", line 822, in _request
    return self._read_response(num)
  File "path\to\venv\lib\site-packages\paramiko\sftp_client.py", line 874, in _read_response
    self._convert_status(msg)
  File "path\to\venv\lib\site-packages\paramiko\sftp_client.py", line 903, in _convert_status
    raise IOError(errno.ENOENT, text)
FileNotFoundError: [Errno 2] No such file
Wing
  • 642
  • 2
  • 5
  • 16

0 Answers0