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

Method ntransfercmd

Lib/ftplib.py:336–389  ·  view source on GitHub ↗

Initiate a transfer over the data connection. If the transfer is active, send a port command and the transfer command, and accept the connection. If the server is passive, send a pasv command, connect to it, and start the transfer command. Either way, return the so

(self, cmd, rest=None)

Source from the content-addressed store, hash-verified

334 return host, port
335
336 def ntransfercmd(self, cmd, rest=None):
337 """Initiate a transfer over the data connection.
338
339 If the transfer is active, send a port command and the
340 transfer command, and accept the connection. If the server is
341 passive, send a pasv command, connect to it, and start the
342 transfer command. Either way, return the socket for the
343 connection and the expected size of the transfer. The
344 expected size may be None if it could not be determined.
345
346 Optional 'rest' argument can be a string that is sent as the
347 argument to a REST command. This is essentially a server
348 marker used to tell the server to skip over any data up to the
349 given marker.
350 """
351 size = None
352 if self.passiveserver:
353 host, port = self.makepasv()
354 conn = socket.create_connection((host, port), self.timeout,
355 source_address=self.source_address)
356 try:
357 if rest is not None:
358 self.sendcmd("REST %s" % rest)
359 resp = self.sendcmd(cmd)
360 # Some servers apparently send a 200 reply to
361 # a LIST or STOR command, before the 150 reply
362 # (and way before the 226 reply). This seems to
363 # be in violation of the protocol (which only allows
364 # 1xx or error messages for LIST), so we just discard
365 # this response.
366 if resp[0] == '2':
367 resp = self.getresp()
368 if resp[0] != '1':
369 raise error_reply(resp)
370 except:
371 conn.close()
372 raise
373 else:
374 with self.makeport() as sock:
375 if rest is not None:
376 self.sendcmd("REST %s" % rest)
377 resp = self.sendcmd(cmd)
378 # See above.
379 if resp[0] == '2':
380 resp = self.getresp()
381 if resp[0] != '1':
382 raise error_reply(resp)
383 conn, sockaddr = sock.accept()
384 if self.timeout is not _GLOBAL_DEFAULT_TIMEOUT:
385 conn.settimeout(self.timeout)
386 if resp[:3] == '150':
387 # this is conditional in case we received a 125
388 size = parse150(resp)
389 return conn, size
390
391 def transfercmd(self, cmd, rest=None):
392 """Like ntransfercmd() but returns only the socket."""

Callers 3

transfercmdMethod · 0.95
ntransfercmdMethod · 0.45
retrfileMethod · 0.45

Calls 10

makepasvMethod · 0.95
sendcmdMethod · 0.95
getrespMethod · 0.95
makeportMethod · 0.95
error_replyClass · 0.85
parse150Function · 0.85
create_connectionMethod · 0.45
closeMethod · 0.45
acceptMethod · 0.45
settimeoutMethod · 0.45

Tested by

no test coverage detected