IOError: [Errno 2] There is no such file - Paramiko put ()

I upload a file via SFTP using Paramiko with sftp.put(localFile, remoteFile) . First I create the necessary directory, if necessary, using

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

this worked sometimes, but sometimes I get 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 

even though the local file definitely exists (and localFile is the correct path to it) and the remote path. There is a discussion here and here on a similar issue, but none of the issues raised there have helped. My server supports the df -hi . Anyone have any advice on this or a possible solution?

EDIT

After the suggestions below, I tried changing the working directory to sftp.chdir(remoteDirectory) , but this call caused the same error as above. This doesn't seem to be just a download problem. Any ideas?

+4
source share
3 answers

There seems to be a problem with the remote folder. Although the remote folder was made before the file was downloaded, it seems that the permissions in the folder prevent the download.

The problem is related to this problem - if I set the open permissions for the folder that I download before downloading, the program may load normally. Although for the permission problem I should get an IOError: [Errno 13] Permission denied , since I made the changes, I did not find any errors.

I'm not sure if this is the answer Parima server, which is the problem, or an error in Paramiko itself that causes IOError: [Errno 2] No such file instead of Errno 13 , but this seems to have solved the problem.

+6
source

IOError is local, so (for some reason) it seems like your local python cannot find localFile . A security check before a call can help identify a problem:

 if os.path.isfile(localFile): sftp.put(localFile, remoteFile) else: raise IOError('Could not find localFile %s !!' % localFile) 

If you are sure that localFile exists, it might just be a path problem - is it localFile in an absolute or relative path? In any case, the above if will catch it.

EDIT

Tracing through paramiko files shows that line 245 sftp_client.py (the one who throws the exception) is actually

 fr = self.file(remotepath, 'wb') 

which is pretty misleading as paramiko throws an IOError for the deleted file! Now I think that remoteFile is either a missing directory or a directory that you do not have access to.

Of interest, you can specify a remote directory

 sftp.listdir(path=os.path.dirname(remoteFile)) 

check that he is there (or maybe he is, and you can write to him)?

+1
source

Are you sure the directory has been created and this is your remote working directory? Paramiko has its own methods for creating new directories and navigating the remote file system. Think using something like:

 sftp.mkdir(remotedirectory) sftp.chdir(remotedirectory) sftp.put(localfile, remotefile) 
+1
source

All Articles