title: IOError: [Errno 2] No such file - Paramiko put()
body: <p>I'm uploading a file via SFTP using <a href="http://www.lag.net/paramiko/" rel="noreferrer">Paramiko</a> with <code>sftp.put(localFile, remoteFile)</code>. I make the necessary directory first if needed with </p>
  
  <pre><code>    makeCommand = 'mkdir -p "' + remotePath + '"'
      ssh.exec_command(makeCommand)
  </code></pre>
  
  <p>this was works sometimes but I'm occasionally getting the following error:</p>
  
  <pre><code>    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 
  </code></pre>
  
  <p>despite the fact that the local file definitely exists (and <code>localFile</code> is the correct path to it) and the remote path is made. 
  There is discussion <a href="https://bugs.launchpad.net/paramiko/+bug/492238" rel="noreferrer">here</a> and <a href="https://stackoverflow.com/questions/11198364/paramiko-get-raises-ioerror-no-such-file-if-server-doesnt-support-df-hi">here</a> on a similar problem but none of the points raised there have helped me. My server supports the <code>df -hi</code> command.
  Has anyone any advice on this or a possible solution?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After suggestions below I tried changing the working directory with <code>sftp.chdir(remoteDirectory)</code> but this call produced the exact same error as above. So it seems this isn't just an upload issue. Any ideas?</p>