def put(self, localpath, remotepath, callback=None, confirm=True):
file_size = os.stat(localpath).st_size<EOL>fl = file(localpath, '<STR_LIT:rb>')<EOL>try:<EOL><INDENT>fr = self.file(remotepath, '<STR_LIT:wb>')<EOL>fr.set_pipelined(True)<EOL>size = <NUM_LIT:0><EOL>try:<EOL><INDENT>while True:<EOL><INDENT>data = fl.read(<NUM_LIT>)<EOL>if len(data) == <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>fr.write(data)<EOL>size += len(data)<EOL>if callback is not None:<EOL><INDENT>callback(size, file_size)<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>fr.close()<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>fl.close()<EOL><DEDENT>if confirm:<EOL><INDENT>s = self.stat(remotepath)<EOL>if s.st_size != size:<EOL><INDENT>raise IOError('<STR_LIT>' % (s.st_size, size))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>s = SFTPAttributes()<EOL><DEDENT>return s<EOL>
Copy a local file (C{localpath}) to the SFTP server as C{remotepath}.
Any exception raised by operations will be passed through.  This
method is primarily provided as a convenience.

The SFTP operations use pipelining for speed.

@param localpath: the local file to copy
@type localpath: str
@param remotepath: the destination path on the SFTP server
@type remotepath: str
@param callback: optional callback function that accepts the bytes
    transferred so far and the total bytes to be transferred
    (since 1.7.4)
@type callback: function(int, int)
@param confirm: whether to do a stat() on the file afterwards to
    confirm the file size (since 1.7.7)
@type confirm: bool

@return: an object containing attributes about the given file
    (since 1.7.4)
@rtype: SFTPAttributes

@since: 1.4