MCPcopy Index your code
hub / github.com/python/cpython / storbinary

Method storbinary

Lib/ftplib.py:479–503  ·  view source on GitHub ↗

Store a file in binary mode. A new port is created for you. Args: cmd: A STOR command. fp: A file-like object with a read(num_bytes) method. blocksize: The maximum data size to read from fp and send over the connection at once. [default:

(self, cmd, fp, blocksize=8192, callback=None, rest=None)

Source from the content-addressed store, hash-verified

477 return self.voidresp()
478
479 def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
480 """Store a file in binary mode. A new port is created for you.
481
482 Args:
483 cmd: A STOR command.
484 fp: A file-like object with a read(num_bytes) method.
485 blocksize: The maximum data size to read from fp and send over
486 the connection at once. [default: 8192]
487 callback: An optional single parameter callable that is called on
488 each block of data after it is sent. [default: None]
489 rest: Passed to transfercmd(). [default: None]
490
491 Returns:
492 The response code.
493 """
494 self.voidcmd('TYPE I')
495 with self.transfercmd(cmd, rest) as conn:
496 while buf := fp.read(blocksize):
497 conn.sendall(buf)
498 if callback:
499 callback(buf)
500 # shutdown ssl layer
501 if _SSLSocket is not None and isinstance(conn, _SSLSocket):
502 conn.unwrap()
503 return self.voidresp()
504
505 def storlines(self, cmd, fp, callback=None):
506 """Store a file in line mode. A new port is created for you.

Callers 2

test_storbinaryMethod · 0.80
test_storbinary_restMethod · 0.80

Calls 7

voidcmdMethod · 0.95
transfercmdMethod · 0.95
voidrespMethod · 0.95
callbackFunction · 0.70
readMethod · 0.45
sendallMethod · 0.45
unwrapMethod · 0.45

Tested by 2

test_storbinaryMethod · 0.64
test_storbinary_restMethod · 0.64