Commit 8196b043 authored by Vincent Pelletier's avatar Vincent Pelletier

ERP5Type.ConnectionPlugin.SFTPConnection: Make file size check conditional.

In some cases, listing files is disallowed. Allow caller to disable
paramiko's default-enabled file size check to support these cases.
parent 5bb3a8dc
...@@ -99,16 +99,16 @@ class FTPConnector(XMLObject): ...@@ -99,16 +99,16 @@ class FTPConnector(XMLObject):
finally: finally:
conn.logout() conn.logout()
def putFile(self, filename, data, remotepath='.'): def putFile(self, filename, data, remotepath='.', confirm=True):
""" Send file to the remote server """ """ Send file to the remote server """
conn = self.getConnection() conn = self.getConnection()
try: try:
if self.isUseTemporaryFileOnWrite(): if self.isUseTemporaryFileOnWrite():
# Simulation transaction system # Simulation transaction system
conn.writeFile(remotepath, '%s.tmp' % filename, data) conn.writeFile(remotepath, '%s.tmp' % filename, data, confirm=confirm)
self.activate(activity='SQLQueue').renameFile('%s/%s.tmp' % (remotepath, filename), self.activate(activity='SQLQueue').renameFile('%s/%s.tmp' % (remotepath, filename),
'%s/%s' % (remotepath, filename)) '%s/%s' % (remotepath, filename))
else: else:
conn.writeFile(remotepath, '%s' % filename, data) conn.writeFile(remotepath, '%s' % filename, data, confirm=confirm)
finally: finally:
conn.logout() conn.logout()
9 10
\ No newline at end of file \ No newline at end of file
...@@ -104,14 +104,14 @@ class SFTPConnection: ...@@ -104,14 +104,14 @@ class SFTPConnection:
raise SFTPError(str(msg) + ' while changing to dir -%r-' % (schema.path,)) raise SFTPError(str(msg) + ' while changing to dir -%r-' % (schema.path,))
return self return self
def writeFile(self, path, filename, data): def writeFile(self, path, filename, data, confirm=True):
""" """
Write data in provided filepath Write data in provided filepath
""" """
filepath = os.path.join(path, filename) filepath = os.path.join(path, filename)
serialized_data = Binary(str(data)) serialized_data = Binary(str(data))
try: try:
self.conn.putfo(StringIO(str(serialized_data)), filepath) self.conn.putfo(StringIO(str(serialized_data)), filepath, confirm=confirm)
except error, msg: except error, msg:
raise SFTPError(str(msg) + ' while writing file %s on %s' % (filepath, path, self.url)) 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