diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index 1f11075..a7e9058 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -533,7 +533,7 @@ class SFTPClient (BaseSFTP): """ return self._cwd - def put(self, localpath, remotepath, callback=None): + def put(self, localpath, remotepath, callback=None, confirm = True): """ Copy a local file (C{localpath}) to the SFTP server as C{remotepath}. Any exception raised by operations will be passed through. This @@ -574,9 +574,12 @@ class SFTPClient (BaseSFTP): fr.close() finally: fl.close() - s = self.stat(remotepath) - if s.st_size != size: - raise IOError('size mismatch in put! %d != %d' % (s.st_size, size)) + if confirm: + s = self.stat(remotepath) + if s.st_size != size: + raise IOError('size mismatch in put! %d != %d' % (s.st_size, size)) + else: + s = SFTPAttributes() return s def get(self, remotepath, localpath, callback=None): diff --git a/tests/test_sftp.py b/tests/test_sftp.py index f9d7270..f191314 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -36,6 +36,7 @@ import unittest import paramiko from stub_sftp import StubServer, StubSFTPServer from loop import LoopSocket +from paramiko.sftp_attr import SFTPAttributes ARTICLE = ''' Insulin sensitivity and liver insulin receptor structure in ducks from two @@ -666,6 +667,33 @@ class SFTPTest (unittest.TestCase): f.close() finally: sftp.unlink(FOLDER + '/zero') + def test_N_put_without_confirm(self): + """ + verify that get/put work. + """ + import os, warnings + warnings.filterwarnings('ignore', 'tempnam.*') + + localname = os.tempnam() + text = 'All I wanted was a plastic bunny rabbit.\n' + f = open(localname, 'wb') + f.write(text) + f.close() + saved_progress = [] + def progress_callback(x, y): + saved_progress.append((x, y)) + res = sftp.put(localname, FOLDER + '/bunny.txt', progress_callback, false) + + self.assertEquals(SFTPAttributes(), res) + + + f = sftp.open(FOLDER + '/bunny.txt', 'r') + self.assertEquals(text, f.read(128)) + f.close() + self.assertEquals((41, 41), saved_progress[-1]) + + os.unlink(localname) + sftp.unlink(FOLDER + '/bunny.txt') def XXX_test_M_seek_append(self): """