带有paramiko的Python sftp错误

带有paramiko的Python sftp错误,python,sftp,paramiko,Python,Sftp,Paramiko,为什么调用get函数时,paramiko出现连接断开错误 class AllowAnythingPolicy(paramiko.MissingHostKeyPolicy): def missing_host_key(self, client, hostname, key): return client = paramiko.SSHClient() client.set_missing_host_key_policy(AllowAnythingPolicy()) clie

为什么调用get函数时,paramiko出现连接断开错误

class AllowAnythingPolicy(paramiko.MissingHostKeyPolicy):
    def missing_host_key(self, client, hostname, key):
        return

client = paramiko.SSHClient()
client.set_missing_host_key_policy(AllowAnythingPolicy())
client.connect('', username='',password='')
sftp.get('','')
我有一个70MB的文件,函数下载20mb后我得到一个错误。 当文件大小小于20mb时,此函数工作正常

这是paramiko日志文件:

DEB [20161115-10:25:47.792] thr=1   paramiko.transport: starting thread (client mode): 0x472a3d0
DEB [20161115-10:25:47.793] thr=1   paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.0.2
DEB [20161115-10:25:47.793] thr=1   paramiko.transport: Remote version/idstring: SSH-2.0-SshServer
INF [20161115-10:25:47.794] thr=1   paramiko.transport: Connected (version 2.0, client SshServer)
DEB [20161115-10:25:47.795] thr=1   paramiko.transport: kex algos:['ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa'] client encrypt:['aes256-ctr', 'aes256-cbc'] server encrypt:['aes256-ctr', 'aes256-cbc'] client mac:['hmac-sha1', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com'] server mac:['hmac-sha1', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com'] client compress:['none'] server compress:['none'] client lang:['en-US'] server lang:['en-US'] kex follows?False
DEB [20161115-10:25:47.795] thr=1   paramiko.transport: Kex agreed: diffie-hellman-group1-sha1
DEB [20161115-10:25:47.796] thr=1   paramiko.transport: Cipher agreed: aes256-ctr
DEB [20161115-10:25:47.796] thr=1   paramiko.transport: MAC agreed: hmac-sha2-256
DEB [20161115-10:25:47.796] thr=1   paramiko.transport: Compression agreed: none
DEB [20161115-10:25:48.054] thr=1   paramiko.transport: kex engine KexGroup1 specified hash_algo <built-in function openssl_sha1>
DEB [20161115-10:25:48.054] thr=1   paramiko.transport: Switch to new keys ...
DEB [20161115-10:25:48.057] thr=1   paramiko.transport: userauth is OK
INF [20161115-10:25:48.137] thr=1   paramiko.transport: Authentication (password) successful!
DEB [20161115-10:25:57.677] thr=2   paramiko.transport: [chan 0] Max packet in: 32768 bytes
DEB [20161115-10:25:57.680] thr=1   paramiko.transport: [chan 0] Max packet out: 32768 bytes
DEB [20161115-10:25:57.681] thr=1   paramiko.transport: Secsh channel 0 opened.
DEB [20161115-10:25:57.682] thr=1   paramiko.transport: [chan 0] Sesch channel 0 request ok
INF [20161115-10:25:57.684] thr=2   paramiko.transport.sftp: [chan 0] Opened sftp connection (server version 3)
DEB [20161115-10:25:57.685] thr=2   paramiko.transport.sftp: [chan 0] stat(b'/GEO/OUT')
DEB [20161115-10:25:57.688] thr=2   paramiko.transport.sftp: [chan 0] normalize(b'/GEO/OUT')
DEB [20161115-10:25:57.690] thr=2   paramiko.transport.sftp: [chan 0] listdir(b'/GEO/OUT/.')
DEB [20161115-10:26:02.008] thr=2   paramiko.transport.sftp: [chan 0] stat(b'/GEO/OUT/test.csv')
DEB [20161115-10:26:02.012] thr=2   paramiko.transport.sftp: [chan 0] open(b'/GEO/OUT/test.csv', 'rb')
DEB [20161115-10:26:02.016] thr=2   paramiko.transport.sftp: [chan 0] open(b'/GEO/OUT/test.csv', 'rb') -> b'2f47454f2f4f55542f746573742e637376'
DEB [20161115-10:28:10.626] thr=1   paramiko.transport: EOF in transport thread
DEB [20161115-10:28:10.626] thr=2   paramiko.transport.sftp: [chan 0] close(b'2f47454f2f4f55542f746573742e637376')
DEB[20161115-10:25:47.792]thr=1 paramiko.transport:启动线程(客户端模式):0x472a3d0
DEB[20161115-10:25:47.793]thr=1 paramiko.transport:Local version/idstring:SSH-2.0-paramiko_2.0.2
DEB[20161115-10:25:47.793]thr=1 paramiko.transport:Remote version/idstring:SSH-2.0-SshServer
INF[20161115-10:25:47.794]thr=1 paramiko.transport:已连接(版本2.0,客户端SshServer)
DEB[20161115-10:25:47.795]thr=1 paramiko.transport:kex算法:['ecdh-sha2-nistp256','ecdh-sha2-nistp384','ecdh-sha2-nistp521','diffie-hellman-group-exchange-sha1','diffie-hellman-group-exchange-sha256','diffie-hellman-group14-sha1','diffie-hellman-group1-sha1']服务器密钥:['ssh-rsa']客户端加密:['aes256-ctr','aes256-cbc']服务器加密:['aes256-ctr','aes256 cbc']客户端mac:['hmac-sha1','hmac-sha2-256','hmac-sha2-512','hmac-ripemd160','hmac-ripemd160@openssh.com“]服务器mac:['hmac-sha1'、'hmac-sha2-256'、'hmac-sha2-512'、'hmac-ripemd160'、'hmac-ripemd160@openssh.com']客户端压缩:['none']服务器压缩:['none']客户端语言:['en-US']服务器语言:[en-US']kex跟在后面?错
DEB[20161115-10:25:47.795]thr=1 paramiko.transport:Kex同意:diffie-hellman-group1-sha1
DEB[20161115-10:25:47.796]thr=1 paramiko.transport:同意密码:aes256中心
DEB[20161115-10:25:47.796]thr=1 paramiko.运输:MAC同意:hmac-sha2-256
DEB[20161115-10:25:47.796]thr=1 paramiko.运输:同意压缩:无
DEB[20161115-10:25:48.054]thr=1 paramiko.transport:kex引擎KexGroup1指定的哈希算法
DEB[20161115-10:25:48.054]thr=1 paramiko.transport:切换到新密钥。。。
DEB[20161115-10:25:48.057]thr=1 paramiko.transport:userauth正常
INF[20161115-10:25:48.137]thr=1 paramiko.transport:身份验证(密码)成功!
DEB[20161115-10:25:57.677]thr=2 paramiko.transport:[chan 0]最大数据包长度:32768字节
DEB[20161115-10:25:57.680]thr=1 paramiko.transport:[chan 0]最大数据包输出:32768字节
DEB[20161115-10:25:57.681]thr=1 paramiko.transport:第0频道已开通。
DEB[20161115-10:25:57.682]thr=1 paramiko.transport:[chan 0]Sesch频道0请求正常
INF[20161115-10:25:57.684]thr=2 paramiko.transport.sftp:[chan 0]已打开sftp连接(服务器版本3)
DEB[20161115-10:25:57.685]thr=2 paramiko.transport.sftp:[chan 0]stat(b'/GEO/OUT')
DEB[20161115-10:25:57.688]thr=2 paramiko.transport.sftp:[chan 0]正常化(b'/GEO/OUT')
DEB[20161115-10:25:57.690]thr=2 paramiko.transport.sftp:[chan 0]listdir(b'/GEO/OUT/)
DEB[20161115-10:26:02.008]thr=2 paramiko.transport.sftp:[chan 0]stat(b'/GEO/OUT/test.csv')
DEB[20161115-10:26:02.012]thr=2 paramiko.transport.sftp:[chan 0]打开(b'/GEO/OUT/test.csv',rb')
DEB[20161115-10:26:02.016]thr=2 paramiko.transport.sftp:[chan 0]打开(b'/GEO/OUT/test.csv','rb')->b'2f47454f2f45542f746573742e637376'
DEB[20161115-10:28:10.626]thr=1 paramiko.transport:传输线程中的EOF
DEB[20161115-10:28:10.626]thr=2 paramiko.transport.sftp:[chan 0]关闭(b'2F47454F2F5542F746573742E637376')
和Python错误:

EOFError                                  Traceback (most recent call last)
C:\Anaconda3\lib\site-packages\paramiko\sftp_client.py in _read_response(self, waitfor)
    759             try:
--> 760                 t, data = self._read_packet()
    761             except EOFError as e:

C:\Anaconda3\lib\site-packages\paramiko\sftp.py in _read_packet(self)
    172     def _read_packet(self):
--> 173         x = self._read_all(4)
    174         # most sftp servers won't accept packets larger than about 32k, so

C:\Anaconda3\lib\site-packages\paramiko\sftp.py in _read_all(self, n)
    158             if len(x) == 0:
--> 159                 raise EOFError()
    160             out += x

EOFError: 

During handling of the above exception, another exception occurred:

SSHException                              Traceback (most recent call last)
<ipython-input-49-b52d34c6bd07> in <module>()
----> 1 sftp.get('/GEO/OUT/test.csv','ESRI_OUT/te.csv')

C:\Anaconda3\lib\site-packages\paramiko\sftp_client.py in get(self, remotepath, localpath, callback)
    719         """
    720         with open(localpath, 'wb') as fl:
--> 721             size = self.getfo(remotepath, fl, callback)
    722         s = os.stat(localpath)
    723         if s.st_size != size:

C:\Anaconda3\lib\site-packages\paramiko\sftp_client.py in getfo(self, remotepath, fl, callback)
    697             fr.prefetch(file_size)
    698             return self._transfer_with_callback(
--> 699                 reader=fr, writer=fl, file_size=file_size, callback=callback
    700             )
    701 

C:\Anaconda3\lib\site-packages\paramiko\sftp_client.py in _transfer_with_callback(self, reader, writer, file_size, callback)
    596         size = 0
    597         while True:
--> 598             data = reader.read(32768)
    599             writer.write(data)
    600             size += len(data)

C:\Anaconda3\lib\site-packages\paramiko\file.py in read(self, size)
    209                 read_size = max(self._bufsize, read_size)
    210             try:
--> 211                 new_data = self._read(read_size)
    212             except EOFError:
    213                 new_data = None

C:\Anaconda3\lib\site-packages\paramiko\sftp_file.py in _read(self, size)
    163         size = min(size, self.MAX_REQUEST_SIZE)
    164         if self._prefetching:
--> 165             data = self._read_prefetch(size)
    166             if data is not None:
    167                 return data

C:\Anaconda3\lib\site-packages\paramiko\sftp_file.py in _read_prefetch(self, size)
    143             if self._prefetch_done or self._closed:
    144                 break
--> 145             self.sftp._read_response()
    146             self._check_exception()
    147         if offset is None:

C:\Anaconda3\lib\site-packages\paramiko\sftp_client.py in _read_response(self, waitfor)
    760                 t, data = self._read_packet()
    761             except EOFError as e:
--> 762                 raise SSHException('Server connection dropped: %s' % str(e))
    763             msg = Message(data)
    764             num = msg.get_int()

SSHException: Server connection dropped:
EOFError回溯(最近一次调用)
C:\Anaconda3\lib\site packages\paramiko\sftp\u client.py in\u read\u响应(self,waitfor)
759尝试:
-->760吨,数据=自读数据包()
761除EOFError as e外:
C:\Anaconda3\lib\site packages\paramiko\sftp.py in_read_package(self)
172 def读取数据包(自身):
-->173 x=自读全部(4)
174#大多数sftp服务器不接受大于32k的数据包,因此
C:\Anaconda3\lib\site packages\paramiko\sftp.py in\u read\u all(self,n)
158如果len(x)==0:
-->159提高EOFError()
160输出+=x
EOFError:
在处理上述异常期间,发生了另一个异常:
SSHException回溯(最近一次呼叫上次)
在()
---->1 sftp.get('/GEO/OUT/test.csv'、'ESRI_OUT/te.csv')
get中的C:\Anaconda3\lib\site packages\paramiko\sftp_client.py(self、remotepath、localpath、callback)
719         """
720,开放(本地路径,“wb”)为fl:
-->721 size=self.getfo(远程路径、fl、回调)
722 s=os.stat(localpath)
723如果s.st_尺寸!=尺寸:
C:\Anaconda3\lib\site packages\paramiko\sftp_client.py在getfo中(self、remotepath、fl、callback)
697 fr.prefetch(文件大小)
698返回自。\u传输\u和\u回调(
-->699读卡器=fr,写卡器=fl,文件大小=文件大小,回调=回调
700             )
701
C:\Anaconda3\lib\site packages\paramiko\sftp\u client.py in\u transfer\u带回调(self、reader、writer、file\u size、callback)
596尺寸=0
597虽然正确:
-->598 data=reader.read(32768)
599写入器。写入(数据)
600尺寸+=透镜(数据)
C:\Anaconda3\lib\site packages\paramiko\file.py处于读取状态(self,size)
209读取大小=最大值(自身大小,读取大小)
210尝试:
-->211新数据=自身读取(读取大小)
212除EOFError外:
213新数据=无
C:\Anaconda3\lib\site packages\paramiko\sftp_file.py in_read(self,size)
163尺寸=最小值(尺寸,自身最大请求尺寸)
164如果自预取:
-->165数据=自读取预取(大小)
166如果数据不是无:
167返回数据
C:\Anaconda3\lib\site packages\paramiko\sftp\u file.py in\u read\u prefetch(self,size)
143如果自我预取完成或自我关闭:
144
class AllowAnythingPolicy(paramiko.MissingHostKeyPolicy):
    def missing_host_key(self, client, hostname, key):
        return

client = paramiko.SSHClient()
client.set_missing_host_key_policy(AllowAnythingPolicy())
client.connect('', username='',password='')
file = sftp.open('','')
file.read # Will get you the file.
remotefile = sftp.open('','')
with remotefile.file(remote_file_path, mode='w') as sftpfile:
    sftpfile.MAX_REQUEST_SIZE = 1024
    sftpfile.write(data)
tr = client.get_transport()
tr.default_max_packet_size = 100000000
tr.default_window_size = 100000000