Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paramiko error: size mismatch in put

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.

like image 727
May Avatar asked Apr 21 '15 19:04

May


1 Answers

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)

like image 153
mmeisner Avatar answered Sep 21 '22 01:09

mmeisner