IOError: [Errno 2] No such file, put() sftp_client

Bug #492238 reported by Amit Chai
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
paramiko
New
Undecided
Unassigned

Bug Description

Hi,

I am uploading zip files to a linux server from xp
some time there is no error, some times it can not upload a specific file.

the test program:

    transport = paramiko.Transport((host, port))
    transport.connect(username = username, password = password)
    sftp = paramiko.SFTPClient.from_transport(transport)

    localpath = 'C:/Program Files/infoio/mklogger/zlog/20091203173444.zip'
    filepath= '/home/amit/tmp/server/uploadedziplogs/zlog/20091203173444.zip'

    sftp.put( localpath,filepath)

    sftp.close()
    transport.close()

the out put:

Traceback (most recent call last):
  File "D:\Project\release_agent\test\test_sftp.py", line 54, in <module>
    sftp.put( localpath,filepath)
  File "C:\Python25\Lib\site-packages\paramiko\sftp_client.py", line 577, in put
    s = self.stat(remotepath)
  File "C:\Python25\Lib\site-packages\paramiko\sftp_client.py", line 337, in stat
    t, msg = self._request(CMD_STAT, path)
  File "C:\Python25\Lib\site-packages\paramiko\sftp_client.py", line 628, in _request
    return self._read_response(num)
  File "C:\Python25\Lib\site-packages\paramiko\sftp_client.py", line 675, in _read_response
    self._convert_status(msg)
  File "C:\Python25\Lib\site-packages\paramiko\sftp_client.py", line 701, in _convert_status
    raise IOError(errno.ENOENT, text)
IOError: [Errno 2] No such file

Revision history for this message
Jim Carroll (mrmaple) wrote :

It's happening for me now too. I'm on Python 2.6 on a Mac client, uploading to a CentOS machine.

Revision history for this message
Jim Carroll (mrmaple) wrote :

bump... or... let me know how I can help fix it. The above stack trace shows the error in stat, by mine is in put...

  File "/Users/jimc/anl/myweb/ZigMyWeb/trunk/deploy_tools.py", line 69, in uploadViaSftp
    sftp.put(src, dest)
  File "build/bdist.macosx-10.3-i386/egg/paramiko/sftp_client.py", line 561, in put
  File "build/bdist.macosx-10.3-i386/egg/paramiko/sftp_client.py", line 245, in open
  File "build/bdist.macosx-10.3-i386/egg/paramiko/sftp_client.py", line 628, in _request
  File "build/bdist.macosx-10.3-i386/egg/paramiko/sftp_client.py", line 675, in _read_response
  File "build/bdist.macosx-10.3-i386/egg/paramiko/sftp_client.py", line 701, in _convert_status
IOError: [Errno 2] No such file

I'm using paramiko 1.7.6 with pycrypto 2.0.1 on Mac 10.6 and putting on a CentOS machine.

Revision history for this message
Jim Carroll (mrmaple) wrote :

May be a red herring... it may just be a problem with authentication.

Once I double checked my credentials, and changed my
   ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
to
   ssh.load_system_host_keys()

I could upload to the server.

Revision history for this message
lszyba1 (szybalski) wrote :

Hello,
I have similar error and I was wondering where in the code should I place this load_system_host_keys()?

I am using this simple to use ssh.py below.

http://media.commandline.org.uk/code/ssh.txt

And in my code I'm just doing:
import ssh
s=ssh.Connection(host=....,usernanme=....,password=....,port=...)
s.put(..file1...)
s.put(..file2)
s.put(...file3)
s.close()

Could somebody point to a proper place/line in the ssh.py code?

This is the error I'm trying to fix.
 File "./upload.py", line 31, in <module>

    s.put('/home/lucas/tmp/sql_report_server/eft_files/%sxxxxx' %date2import)

  File "/home/lucas/tmp/sql_report_server/ssh.py", line 67, in put

    self._sftp.put(localpath, remotepath)

  File "/var/lib/python-support/python2.5/paramiko/sftp_client.py", line 562, in put

    s = self.stat(remotepath)

  File "/var/lib/python-support/python2.5/paramiko/sftp_client.py", line 332, in stat

    t, msg = self._request(CMD_STAT, path)

  File "/var/lib/python-support/python2.5/paramiko/sftp_client.py", line 609, in _request

    return self._read_response(num)

  File "/var/lib/python-support/python2.5/paramiko/sftp_client.py", line 656, in _read_response

    self._convert_status(msg)

  File "/var/lib/python-support/python2.5/paramiko/sftp_client.py", line 682, in _convert_status

    raise IOError(errno.ENOENT, text)

IOError: [Errno 2] No such file

Thanks,
Lucas

Revision history for this message
Lance Sanders (lance-f-sanders) wrote :

I've done some research on this and verified that the reason for this error is because the call to sftp.stat() fails. This is most likely because the SFTP server doesn't not support the df -hi command.

If you login to the remote machine from the command line and type.

sftp> df -hi .

You'll most likely get something like:

Server does not support <email address hidden> extension

Perhaps there is another method to determine file stats via sftp?

Revision history for this message
Alan Rotman (alan-actcom) wrote :

I have the same problem as Lance.
I need to put a file on a remote server that does NOT support "df -hi ."

Is there a solution for this?
Perhaps just have sftp.put NOT verify the filesize with self.stat?

Revision history for this message
Alan Rotman (alan-actcom) wrote :

Is it a reasonable solution to just comment out the stat at the end of put in sftp_client.py?
Since the sftp server does not support stat, ...

        #s = self.stat(remotepath)
        #if s.st_size != size:
        # raise IOError('size mismatch in put! %d != %d' % (s.st_size, size))
        #return s

Revision history for this message
dude (blot-romain) wrote :

Aloha,

4 years later I have the same problem ... No idea how to fix it. Someone found the answer?

Mahalo

Revision history for this message
William (llama231) wrote :

Greetings,

I have found a solution to a similar issue.

This fails:

srv = pysftp.Connection(~)
srv.put(localPath,remotePath)

This works:

srv = pysftp.Connection(~)
srv.chdir(remotePath)
srv.put(localPath)

Not sure how useful this is, but it worked for me.

Revision history for this message
Don Pate (depate1) wrote :

William,
Your solution worked for me, 9 years after you posted it (on python 3.8) . I appreciate you taking the time to post this answer. Many thanks to you!

-Don

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.