summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--paramiko/sftp_client.py11
-rwxr-xr-xtests/test_sftp.py28
2 files changed, 35 insertions, 4 deletions
diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py
index 1f110755..a7e90588 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 f9d72709..f191314a 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):
"""