From a88b8c8c0f591a3bfa8d7984343a27815184f495 Mon Sep 17 00:00:00 2001 From: "Jeremy T. Bouse" Date: Sun, 29 May 2011 08:16:54 -0400 Subject: Imported Upstream version 1.7.7.1 --- docs/paramiko.sftp_client-pysrc.html | 394 ++++++++++++++++++----------------- 1 file changed, 200 insertions(+), 194 deletions(-) (limited to 'docs/paramiko.sftp_client-pysrc.html') diff --git a/docs/paramiko.sftp_client-pysrc.html b/docs/paramiko.sftp_client-pysrc.html index cb1c6ea..f55736a 100644 --- a/docs/paramiko.sftp_client-pysrc.html +++ b/docs/paramiko.sftp_client-pysrc.html @@ -128,7 +128,7 @@ paramiko.SFTPServerInterface.stat" class="py-name" href="#" onclick="return docl 69 @raise SSHException: if there's an exception while negotiating 70 sftp 71 """ - 72 BaseSFTP. 72 BaseSFTP.533 """ 534 return self._cwd 535 -
536 - def put(self, localpath, remotepath, callback=None): +
536 - def put(self, localpath, remotepath, callback=None, confirm=True):
537 """ 538 Copy a local file (C{localpath}) to the SFTP server as C{remotepath}. 539 Any exception raised by operations will be passed through. This @@ -1248,37 +1247,41 @@ paramiko.SFTPServerInterface.stat" class="py-name" href="#" onclick="return docl 549 transferred so far and the total bytes to be transferred 550 (since 1.7.4) 551 @type callback: function(int, int) -552 @return: an object containing attributes about the given file -553 (since 1.7.4) -554 @rtype: SFTPAttributes +552 @param confirm: whether to do a stat() on the file afterwards to +553 confirm the file size (since 1.7.7) +554 @type confirm: bool 555 -556 @since: 1.4 -557 """ -558 file_size = os.556 @return: an object containing attributes about the given file +557 (since 1.7.4) +558 @rtype: SFTPAttributes +559 +560 @since: 1.4 +561 """ +562 file_size = os.stat(localpath).st_size -559 fl = 563 fl = file(localpath, 'rb') -560 try: -561 fr = self.564 try: +565 fr = self.file(remotepath, 'wb') -562 fr.set_pipelined(True) -563 size = 0 -564 try: -565 while True: -566 data = fl.566 fr.set_pipelined(True) +567 size = 0 +568 try: +569 while True: +570 data = fl.read(32768) -567 if len(data) == 0: -568 break -569 fr.571 if len(data) == 0: +572 break +573 fr.write(data) -570 size += len(data) -571 if callback is not None: -572 callback(size, file_size) -573 finally: -574 fr.574 size += len(data) +575 if callback is not None: +576 callback(size, file_size) +577 finally: +578 fr.close() -575 finally: -576 fl.579 finally: +580 fl.close() -577 s = self.581 if confirm: +582 s = self.stat(remotepath) -578 if s.st_size != size: -579 raise IOError('size mismatch in put! %d != %d' % (s.st_size, size)) -580 return s -
581 -
582 - def get(self, remotepath, localpath, callback=None): -
583 """ -584 Copy a remote file (C{remotepath}) from the SFTP server to the local -585 host as C{localpath}. Any exception raised by operations will be -586 passed through. This method is primarily provided as a convenience. -587 -588 @param remotepath: the remote file to copy -589 @type remotepath: str -590 @param localpath: the destination path on the local host -591 @type localpath: str -592 @param callback: optional callback function that accepts the bytes -593 transferred so far and the total bytes to be transferred -594 (since 1.7.4) -595 @type callback: function(int, int) -596 -597 @since: 1.4 -598 """ -599 fr = self.file(remotepath, 'rb') -600 file_size = self.583 if s.st_size != size: +584 raise IOError('size mismatch in put! %d != %d' % (s.st_size, size)) +585 else: +586 s = SFTPAttributes() +587 return s +
588 +
589 - def get(self, remotepath, localpath, callback=None): +
590 """ +591 Copy a remote file (C{remotepath}) from the SFTP server to the local +592 host as C{localpath}. Any exception raised by operations will be +593 passed through. This method is primarily provided as a convenience. +594 +595 @param remotepath: the remote file to copy +596 @type remotepath: str +597 @param localpath: the destination path on the local host +598 @type localpath: str +599 @param callback: optional callback function that accepts the bytes +600 transferred so far and the total bytes to be transferred +601 (since 1.7.4) +602 @type callback: function(int, int) +603 +604 @since: 1.4 +605 """ +606 fr = self.file(remotepath, 'rb') +607 file_size = self.stat(remotepath).st_size -601 fr.prefetch() -602 try: -603 fl = file(localpath, 'wb') -604 try: -605 size = 0 -606 while True: -607 data = fr.stat(remotepath).st_size +608 fr.prefetch() +609 try: +610 fl = file(localpath, 'wb') +611 try: +612 size = 0 +613 while True: +614 data = fr.read(32768) -608 if len(data) == 0: -609 break -610 fl.write(data) -611 size += len(data) -612 if callback is not None: -613 callback(size, file_size) -614 finally: -615 fl.read(32768) +615 if len(data) == 0: +616 break +617 fl.write(data) +618 size += len(data) +619 if callback is not None: +620 callback(size, file_size) +621 finally: +622 fl.close() -616 finally: -617 fr.close() +623 finally: +624 fr.close() -618 s = os.close() +625 s = os.stat(localpath) -619 if s.st_size != size: -620 raise IOError('size mismatch in get! %d != %d' % (s.st_size, size)) -
621 -622 -623 ### internals... -624 -625 -
626 - def _request(self, t, *arg): -
627 num = self._async_request(type(None), t, *arg) -628 return self._read_response(num) -
629 -
630 - def _async_request(self, fileobj, t, *arg): -
631 # this method may be called from other threads (prefetch) -632 self._lock.acquire() -633 try: -634 msg = Message() -635 msg.add_int(self.request_number) -636 for item in arg: -637 if type(item) is int: -638 msg.add_int(item) -639 elif type(item) is long: -640 msg.add_int64(item) -641 elif type(item) is str: -642 msg.add_string(item) -643 elif type(item) is SFTPAttributes: -644 item._pack(msg) -645 else: -646 raise Exception('unknown type for %r type %r' % (item, type(item))) -647 num = self.request_number -648 self._expecting[num] = fileobj -649 self._send_packet(t, str(msg)) -650 self.request_number += 1 -651 finally: -652 self._lock.release() -653 return num -
654 -
655 - def _read_response(self, waitfor=None): -
656 while True: -657 try: -658 t, data = self._read_packet() -659 except EOFError, e: -660 raise SSHException('Server connection dropped: %s' % (str(e),)) -661 msg = Message(data) -662 num = msg.get_int() -663 if num not in self._expecting: -664 # might be response for a file that was closed before responses came back -665 self._log(stat(localpath) +626 if s.st_size != size: +627 raise IOError('size mismatch in get! %d != %d' % (s.st_size, size)) +
628 +629 +630 ### internals... +631 +632 +
633 - def _request(self, t, *arg): +
634 num = self._async_request(type(None), t, *arg) +635 return self._read_response(num) +
636 +
637 - def _async_request(self, fileobj, t, *arg): +
638 # this method may be called from other threads (prefetch) +639 self._lock.acquire() +640 try: +641 msg = Message() +642 msg.add_int(self.request_number) +643 for item in arg: +644 if type(item) is int: +645 msg.add_int(item) +646 elif type(item) is long: +647 msg.add_int64(item) +648 elif type(item) is str: +649 msg.add_string(item) +650 elif type(item) is SFTPAttributes: +651 item._pack(msg) +652 else: +653 raise Exception('unknown type for %r type %r' % (item, type(item))) +654 num = self.request_number +655 self._expecting[num] = fileobj +656 self._send_packet(t, str(msg)) +657 self.request_number += 1 +658 finally: +659 self._lock.release() +660 return num +
661 +
662 - def _read_response(self, waitfor=None): +
663 while True: +664 try: +665 t, data = self._read_packet() +666 except EOFError, e: +667 raise SSHException('Server connection dropped: %s' % (str(e),)) +668 msg = Message(data) +669 num = msg.get_int() +670 if num not in self._expecting: +671 # might be response for a file that was closed before responses came back +672 self._log(DEBUG, 'Unexpected response #%d' % (num,)) -666 if waitfor is None: -667 # just doing a single check -668 break -669 continue -670 fileobj = self._expecting[num] -671 del self._expecting[num] -672 if num == waitfor: -673 # synchronous -674 if t == DEBUG, 'Unexpected response #%d' % (num,)) +673 if waitfor is None: +674 # just doing a single check +675 break +676 continue +677 fileobj = self._expecting[num] +678 del self._expecting[num] +679 if num == waitfor: +680 # synchronous +681 if t == CMD_STATUS: -675 self._convert_status(msg) -676 return t, msg -677 if fileobj is not type(None): -678 fileobj._async_response(t, msg) -679 if waitfor is None: -680 # just doing a single check -681 break -682 return (None, None) -
683 -
684 - def _finish_responses(self, fileobj): -
685 while fileobj in self._expecting.values(): -686 self._read_response() -687 fileobj._check_exception() -
688 -
689 - def _convert_status(self, msg): -
690 """ -691 Raises EOFError or IOError on error status; otherwise does nothing. -692 """ -693 code = msg.get_int() -694 text = msg.get_string() -695 if code == CMD_STATUS: +682 self._convert_status(msg) +683 return t, msg +684 if fileobj is not type(None): +685 fileobj._async_response(t, msg) +686 if waitfor is None: +687 # just doing a single check +688 break +689 return (None, None) +
690 +
691 - def _finish_responses(self, fileobj): +
692 while fileobj in self._expecting.values(): +693 self._read_response() +694 fileobj._check_exception() +
695 +
696 - def _convert_status(self, msg): +
697 """ +698 Raises EOFError or IOError on error status; otherwise does nothing. +699 """ +700 code = msg.get_int() +701 text = msg.get_string() +702 if code == SFTP_OK: -696 return -697 elif code == SFTP_OK: +703 return +704 elif code == SFTP_EOF: -698 raise EOFError(text) -699 elif code == SFTP_EOF: +705 raise EOFError(text) +706 elif code == SFTP_NO_SUCH_FILE: -700 # clever idea from john a. meinel: map the error codes to errno -701 raise IOError(errno.ENOENT, text) -702 elif code == SFTP_NO_SUCH_FILE: +707 # clever idea from john a. meinel: map the error codes to errno +708 raise IOError(errno.ENOENT, text) +709 elif code == SFTP_PERMISSION_DENIED: -703 raise IOError(errno.EACCES, text) -704 else: -705 raise IOError(text) -
706 -
707 - def _adjust_cwd(self, path): -
708 """ -709 Return an adjusted path if we're emulating a "current working -710 directory" for the server. -711 """ -712 if type(path) is unicode: -713 path = path.encode('utf-8') -714 if self._cwd is None: -715 return path -716 if (len(path) > 0) and (path[0] == '/'): -717 # absolute path -718 return path -719 if self._cwd == '/': -720 return self._cwd + path -721 return self._cwd + '/' + path -
722 -723 -
724 -class SFTP (SFTPClient): -
725 "an alias for L{SFTPClient} for backwards compatability" -726 pass -
727