Paramiko kann keine großen Dateien> 1 GB herunterladen

def download():
if os.path.exists( dst_dir_path ) == False:
    logger.error( "Cannot access destination folder %s. Please check path and permissions. " % ( dst_dir_path ))
    return 1
elif os.path.isdir( dst_dir_path ) == False:
    logger.error( "%s is not a folder. Please check path. " % ( dst_dir_path ))
    return 1

file_list = None
#transport = paramiko.Transport(( hostname, port)) 
paramiko.util.log_to_file('paramiko.log')
ssh = paramiko.SSHClient() 
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
#transport
try:
    ssh.connect( hostname, username=username, password=password, timeout=5.0) 
    #transport.connect(username=username, password=password ) 
except Exception, err:
    logger.error( "Failed to connect to the remote server. Reason: %s" % ( str(err) ) )
    return 1

try:
    #sftp = paramiko.SFTPClient.from_transport(transport)
    sftp = ssh.open_sftp() 
except Exception, err:
    logger.error( "Failed to start SFTP session from connection to %s. Check that SFTP service is running and available. Reason: %s" % ( hostname, str(err) ))
    return 1

try:    
    sftp.chdir(src_dir_path)
    #file_list = sftp.listdir(path="%s" % ( src_dir_path ) )
    file_list = sftp.listdir()

except Exception, err:
    logger.error( "Failed to list files in folder %s. Please check path and permissions. Reason: %s" % ( src_dir_path, str(err) ))
    return 1
match_text = re.compile( file_mask )
download_count = 0
for file in file_list:         
    # Here is an item name... but is it a file or directory?         
    #logger.info( "Downloading file %s." % ( file ) )
    if not re.match( file_mask, file ):
        continue
    else:
        logger.info( "File \"%s\" name matched file mask \"%s\". matches %s.Processing file..." % ( file, file_mask, (match_text.match( file_mask ) ) ) )
    src_file_path = "./%s" % ( file )
    dst_file_path = "/".join( [ dst_dir_path, file]   )
    retry_count = 0
    while True:
        try:
            logger.info( "Downloading file %s to %s."  % ( file, dst_file_path ) )
            #sftp.get( file, dst_file_path, callback=printTotals ) #sftp.get( remote file, local file )
            sftp.get( file, dst_file_path) #sftp.get( remote file, local file )
            logger.info( "Successfully downloaded file %s to %s."  % ( file, dst_file_path ) )
            download_count += 1
            break
        except Exception, err:
            if retry_count == retry_threshold:
                logger.error( "Failed to download %s to %s. Reason: %s." % ( file, dst_file_path, str(err) ) )
                sftp.close() 
                #transport.close()
                return 1
            else:
                logger.error( "Failed to download %s to %s. Reason: %s." % ( file, dst_file_path, str(err) ) )
                retry_count +=1

sftp.close() 
transport.close() 
logger.info( "%d files downloaded." % ( download_count ) )
return 0

Wenn ich die folgende Funktion ausführe, lädt sie die Quelldatei ungefähr 3 Minuten lang herunter und schließt dann die Sitzung, obwohl nur 38-41 MB (variiert) einer 1-1,6-GB-Datei heruntergeladen wurden.

In der Paramiko-Protokolldatei sieht es so aus, als ob die SSh-Verbindung geöffnet bleibt, während die SFTP-Sitzung geschlossen wird:

DEB [20120913-10: 05: 00.894] thr = 1 paramiko.transport: Wechsel zu neuen Schlüsseln ... DEB [20120913-10: 05: 06.953] thr = 1 paramiko.transport: Rekeying (Treffer 401 Pakete, 1053444 Bytes empfangen ) DEB [20120913-10: 05: 07.391] thr = 1 paramiko.transport: kex algos: ['diffie-hellman-group1-sha1', 'diffie-hellman-group-exchange-sha1'] Serverschlüssel: ['ssh -dss '] Clientverschlüsselung: [' aes256-ctr ',' aes192-ctr ',' aes128-ctr ',' aes256-cbc ',' aes192-cbc ',' aes128-cbc ',' twofish-cbc ', "blowfish-cbc", "3des-cbc", "arcfour"] Serververschlüsselung: ["aes256-ctr", "aes192-ctr", "aes128-ctr", "aes256-cbc", "aes192-cbc", 'aes128-cbc', 'twofish-cbc', 'blowfish-cbc', '3des-cbc', 'arcfour'] client mac: ['hmac-sha1', 'hmac-sha1-96', 'hmac-md5 ',' hmac-md5-96 ',' [email protected] '] Server-Mac: [' hmac-sha1 ',' hmac-sha1-96 ',' hmac-md5 ',' hmac-md5-96 ',' [email protected] '] Client-Komprimierung: [' [email protected] ',' zlib ',' none '] Server-Komprimierung: [' [email protected] ',' zlib ',' none '] client lang: [' '] server lang: [' '] kex follows? False DEB [20120913- 10: 05: 07.421] thr = 1 paramiko.transport: Verschlüsselung vereinbart: local = aes128-ctr, remote = aes128-ctr DEB [20120913-10: 05: 07.421] thr = 1 paramiko.transport: using kex diffie-hellman- group1-sha1; Serverschlüsseltyp ssh-dss; Chiffre: lokale aes128-ctr, entfernte aes128-ctr; mac: lokales hmac-sha1, entferntes hmac-sha1; Komprimierung: lokal keine, remote keine DEB [20120913-10: 05: 07.625] thr = 1 paramiko.transport: Zu neuen Schlüsseln wechseln ... INF [20120913-10: 05: 10.374] thr = 2 paramiko.transport.sftp: [Chan 1] SFTP-Sitzung geschlossen. DEB [20120913-10: 05: 10.388] thr = 2 paramiko.transport: [chan 1] EOF gesendet (1)

Nach diesem Punkt wird das Skript mit dieser Ausnahme beendet (aus dem sftp.get () try / except-Block)

Es sind nicht genügend Ressourcen vorhanden, um die Anforderung abzuschließen

Das System selbst hat Gigabyte freien Speicherplatz, das ist also nicht das Problem.

Die gleiche Übertragung, bei der die parakmiko fehlschlägt, funktioniert auch mit FileZilla und der Java-App, die ich vor Jahren für SFTP-Übertragungen geschrieben habe. Ich denke, es ist ein Problem mit Paramiko.

Dies läuft unter Windows XP und Windows Server 2003.

Ich habe versucht, Paramko 1.17 so zu patchen, dass es die Schlüssel häufiger aktualisiert, aber die Übertragung löst immer noch eine Ausnahme aus. Python 2.7.3 Paramiko 1.7 mit dem Patch Windows 2003 Sevfer

Ideen?

Zusätzliche Informationen: Unter Windows XP SP3 und Windows 2003 Server schlägt genau dasselbe Verhalten und dieselben Fehlermeldungen fehl. Informationen zu sys.version Windows XP Workstation: '2.7.3 (Standard, 10. April 2012, 23:31:26) [MSC v.1500 32 Bit (Intel)]' Windows 2003 Server: '2.7.3 (Standard, 10. April 2012, 23:31:26) 2012, 23:31:26) [MSC v.1500 32 Bit (Intel)] 'Ich habe die Datei packet.py gepatcht, um die Zeit zwischen den Schlüsselerneuerungen zu verkürzen. Es hatte keine Auswirkungen auf das Verhalten von sftp.get ().

Antworten auf die Frage(4)

Ihre Antwort auf die Frage