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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With