Paramiko error: size mismatch in put
Asked Answered
C

1

12

I am trying to copy few files from my local windows directory to remote linux dir.

It is working for file having same kind of extension. But breaks when there are different extensions in a folder.

The Code:

import os
import glob
import paramiko
glob_pattern='*.*'
try:
    ssh.connect(host,username=user,password=pwd)
    ftp = ssh.open_sftp()

    try:
        ftp.mkdir(dir_remote)
        command=dir_remote+'/setuplog'
        ftp.mkdir(command)
        commande=dir_remote+'/emsfolder'
        ftp.mkdir(commande)

        try:
            for fname in glob.glob(uploadfolder + os.sep + glob_pattern):
                local_file = os.path.join(uploadfolder, fname)
                remote_file = dir_remote + '/' + os.path.basename(local_file)
                ftp.put(local_file,remote_file)
                ftp.chmod(remote_file ,0777)
        except IOError, e:
            print (e)


    except IOError, e:
            print (e)


except paramiko.AuthenticationException, ae:
    print (ae)
finally:
    ssh.close()

I was trying to transfer 2 files only(1.sh and 2.pl). While 1.sh got copied a 0 byte 2.pl file is created at the remote server and then I get The Error:

size mismatch in put!  0 != 2200

I am using:

   python 2.7, Paramiko - 1.15.2

Kindly help.

Commissariat answered 21/4, 2015 at 19:38 Comment(1)
Did you solve it? I have similar issue when copied file with different extensions.Superfluity
S
19

I doubt this has anything to do with different extensions in a folder. The code in paramiko's sftp_client.py:putfo() reads at the end:

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

I had a similar issue and it turned out that the remote filesystem was full and thus paramiko couldn't write/put the file.

BTW, instead of uploadfolder + os.sep + glob_pattern (and similar) you can use os.path.join(uploadfolder, glob_pattern)

Shellacking answered 15/6, 2016 at 11:29 Comment(1)
+1 for remote filesystem being full. was stuck for some time with this as well as sftp.open(...) then write() producing a nondescript IOErrorProkopyevsk

© 2022 - 2024 — McMap. All rights reserved.