Search code examples
pythonpython-2.7sftpparamiko

IOError: [Errno 2] No such file - Paramiko put()


I'm uploading a file via SFTP using Paramiko with sftp.put(localFile, remoteFile). I make the necessary directory first if needed with

    makeCommand = 'mkdir -p "' + remotePath + '"'
    ssh.exec_command(makeCommand)

this was works sometimes but I'm occasionally getting the following error:

    sftp.put(localFile, remoteFile)
    File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 565, in put
    File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 245, in open
    File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 635, in _request
    File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 682, in _read_response
    File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 708, in _convert_status
    IOError: [Errno 2] No such file 

despite the fact that the local file definitely exists (and localFile is the correct path to it) and the remote path is made. There is discussion here and here on a similar problem but none of the points raised there have helped me. My server supports the df -hi command. Has anyone any advice on this or a possible solution?

EDIT

After suggestions below I tried changing the working directory with sftp.chdir(remoteDirectory) but this call produced the exact same error as above. So it seems this isn't just an upload issue. Any ideas?


Solution

  • It seems to be a remote folder permission problem. Although the remote folder was made before the file was uploaded, it appears the permissions on the folder were preventing an upload.

    The problem is linked to this issue - if I set open permissions on the folder I'll be uploading to before I upload, the program can upload fine. Although for a permission issue I should be getting IOError: [Errno 13] Permission denied, since I made the changes I haven't encountered any errors.

    I'm not sure if it's the response the server is giving Paramiko which is the issue, or a bug in Paramiko itself which is causing IOError: [Errno 2] No such file instead of a Errno 13, but this appears to have solved the problem.