Skip to content

Commit

Permalink
added functionality to skip verifying the file, which works around sf…
Browse files Browse the repository at this point in the history
…tp servers that remove the file immediately after it's been closed.
  • Loading branch information
larrywright committed Dec 18, 2009
1 parent cb913d5 commit b4ee844
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
11 changes: 7 additions & 4 deletions paramiko/sftp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def getcwd(self):
"""
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
Expand Down Expand Up @@ -574,9 +574,12 @@ def put(self, localpath, remotepath, callback=None):
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):
Expand Down
28 changes: 28 additions & 0 deletions tests/test_sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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
Expand Down Expand Up @@ -666,6 +667,33 @@ def test_M_bad_readv(self):
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):
"""
Expand Down

0 comments on commit b4ee844

Please sign in to comment.