Bugzilla – Attachment 699 Details for
Bug 916
SFTP over SSH died after roughly 20MB when asking for >64k chunks
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Python script demonstrating bug
foosftp.py (text/plain), 4.44 KB, created by
Paul Swartz
on 2004-08-20 02:35:35 AEST
(
hide
)
Description:
Python script demonstrating bug
Filename:
MIME Type:
Creator:
Paul Swartz
Created:
2004-08-20 02:35:35 AEST
Size:
4.44 KB
patch
obsolete
>#!/usr/bin/env python ># Requires Twisted (from twistedmatrix.com) > >from twisted.conch.ssh import transport, userauth, connection, common, keys, channel, filetransfer >from twisted.internet import defer, protocol, reactor >from twisted.python import log >import struct, sys, getpass, os > >USER = 'z3p' # replace this with a valid username >HOST = 'localhost' # and a valid host >DIRECTORY = 'sftptest' # directory relative to HOME from which to download (should contain only files > > ># to generate a bunch of files, try: ># import os ># for i in range(50): ># os.system('dd if=/dev/urandom of=%05i bs=1k count=500' % i) > > > > >#log.startLogging(sys.stderr) >class SimpleTransport(transport.SSHClientTransport): > def verifyHostKey(self, hostKey, fingerprint): > print 'host key fingerprint: %s' % fingerprint > return defer.succeed(1) > > def connectionSecure(self): > self.requestService( > SimpleUserAuth(USER, > SimpleConnection())) > >class SimpleUserAuth(userauth.SSHUserAuthClient): > def getGenericAnswers(self, name, instruction, prompts): > print name > print instruction > l = [] > for p, e in prompts: > if e: > l.append(raw_input(p)) > else: > l.append(getpass.getpass(p)) > return defer.succeed(l) > > def getPassword(self): > return defer.succeed(getpass.getpass("%s@%s's password: " % (USER, HOST))) > >class SimpleConnection(connection.SSHConnection): > def serviceStarted(self): > # both local-win-size and local-max-packet are 2**20 > self.openChannel(SFTPChannel(2**20, 2**20, self)) > >class SFTPChannel(channel.SSHChannel): > name = 'session' > > def openFailed(self, reason): > print 'sftp failed', reason > > def channelOpen(self, ignoredData): > self.data = '' > d = self.conn.sendRequest(self, 'subsystem', common.NS('sftp'), wantReply = 1) > d.addCallback(self._cbRequest) > > def _cbRequest(self, ignored): > self.client = FileTransferClient() > self.client.makeConnection(self) > self.dataReceived = self.client.dataReceived > > def closed(self): > self.client.connectionLost('foo') > reactor.stop() > >class FileTransferClient(filetransfer.FileTransferClient): > > def extReceived(self, t,d): > sys.stderr.write(d) > > def gotServerVersion(self, version, d): > print version, d > self.files = [] > self.openDirectory(DIRECTORY).addCallback(self._cbOpenDir) > > def _cbOpenDir(self, d): > self._cbDirRead([], d) > > def _cbDirRead(self, files, d): > self.files.extend(files) > d.read().addCallback(self._cbDirRead, d).addErrback(self._ebDirRead, d) > > def _ebDirRead(self, f, d): > f.trap(filetransfer.SFTPError) > if f.value.code != filetransfer.FX_EOF: > return f > d.close() > self.files.sort() > print [x[0] for x in self.files] > self.startReading() > > def startReading(self): > if not self.files: > print 'FINISHED' > self.transport.loseConnection() > reactor.stop() > return > filename, longname, attrs = self.files.pop(0) > if filename[0] == '.': > return self.startReading() > d = self.openFile('%s/%s' % (DIRECTORY,filename), filetransfer.FXF_READ, {}) > d.addCallback(self._cbOpenFile, filename) > > def _cbOpenFile(self, h, f): > print 'opened %s' % f > self._cbGotData('', h, 0) > > def _cbGotData(self, data, h, offset): > if data: > print 'got %s bytes' % len(data) > > d = h.readChunk(offset+len(data), 2**16+1) > d.addCallback(self._cbGotData, h, offset+len(data)) > d.addErrback(self._ebGotData, h, offset) > > def _ebGotData(self, f, h, total): > f.trap(filetransfer.SFTPError) > if f.value.code != filetransfer.FX_EOF: > return f > print 'closing, got %i bytes' % total > h.close() > self.startReading() > > def childConnectionLost(self, *args): pass > def childDataReceived(self, child, data): > if child == 1: > self.dataReceived(data) ># else: ># sys.stderr.write(data) > > def processEnded(self, *args): > print args > ># uncomment second line (and comment out first) to connect directly to ># the sftp-server binary > >protocol.ClientCreator(reactor, SimpleTransport).connectTCP(HOST, 80) >#reactor.spawnProcess(FileTransferClient(), '/usr/lib/sftp-server', ['sftp-server']) >reactor.run()
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 916
: 699 |
812