Commit 96102b13 authored by Jérome Perrin's avatar Jérome Perrin

SFTP: support old versions of paramiko

parent 83fd85b0
......@@ -27,7 +27,7 @@
#
##############################################################################
import os, socket
import os, socket, tempfile
from urlparse import urlparse
from socket import error
from xmlrpclib import Binary
......@@ -90,7 +90,15 @@ class SFTPConnection:
filepath = os.path.join(path, filename)
serialized_data = Binary(str(data))
try:
self.conn.putfo(StringIO(str(serialized_data)), filepath, 0, None, True)
if hasattr(self.conn, 'putfo'):
# paramiko >= v1.10.0
self.conn.putfo(StringIO(str(serialized_data)), filepath, 0, None, True)
else:
# older paramiko version
with tempfile.NamedTemporaryFile() as tmpfile:
tmpfile.write(str(serialized_data))
tmpfile.flush()
self.conn.put(tmpfile.name, filepath)
except error, msg:
raise SFTPError(str(msg) + ' while writing file %s on %s' % (filepath, path, self.url))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment