ich möchte mit Paramiko ein BytesIO-Objekt hochladen, in dem eine Zip enthalten ist. Irgendwie funktioniert das aber nicht so ganz :K
Code: Alles auswählen
import sys, io, zipfile, paramiko
dateien = ["/home/user/datei1.txt", "/home/user/datei2.txt"]
def create_zip(files):
file_object = io.BytesIO()
with zipfile.ZipFile(file_object, "w") as myzip:
for file_entry in files:
myzip.write(file_entry)
return file_object
gezippt = create_zip(dateien)
sys.getsizeof(gezippt)
#Da ist etwas „drin“
myzip = zipfile.ZipFile(gezippt, "r")
myzip.namelist()
#Inhalt wird auch angezeigt.
ssh_client = paramiko.SSHClient()
ssh_client.load_system_host_keys()
ssh_client.connect("server", username="benutzername")
sftp = ssh_client.open_sftp()
normalbyteio = io.BytesIO(b"blablblab")
sftp.putfo(normalbyteio, "/home/user/test.txt")
#Das klappt, das ist nachher in einer Datei auf dem Server.
sftp.putfo(gezippt, "/home/user/zipdatei.zip")
#Hier ist nachher nur eine leere Datei zu finden.