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

Method retrfile

Lib/urllib/request.py:1804–1846  ·  view source on GitHub ↗
(self, file, type)

Source from the content-addressed store, hash-verified

1802 self.ftp.cwd(_target)
1803
1804 def retrfile(self, file, type):
1805 import ftplib
1806 self.endtransfer()
1807 if type in ('d', 'D'): cmd = 'TYPE A'; isdir = 1
1808 else: cmd = 'TYPE ' + type; isdir = 0
1809 try:
1810 self.ftp.voidcmd(cmd)
1811 except ftplib.all_errors:
1812 self.init()
1813 self.ftp.voidcmd(cmd)
1814 conn = None
1815 if file and not isdir:
1816 # Try to retrieve as a file
1817 try:
1818 cmd = 'RETR ' + file
1819 conn, retrlen = self.ftp.ntransfercmd(cmd)
1820 except ftplib.error_perm as reason:
1821 if str(reason)[:3] != '550':
1822 raise URLError(f'ftp error: {reason}') from reason
1823 if not conn:
1824 # Set transfer mode to ASCII!
1825 self.ftp.voidcmd('TYPE A')
1826 # Try a directory listing. Verify that directory exists.
1827 if file:
1828 pwd = self.ftp.pwd()
1829 try:
1830 try:
1831 self.ftp.cwd(file)
1832 except ftplib.error_perm as reason:
1833 raise URLError('ftp error: %r' % reason) from reason
1834 finally:
1835 self.ftp.cwd(pwd)
1836 cmd = 'LIST ' + file
1837 else:
1838 cmd = 'LIST'
1839 conn, retrlen = self.ftp.ntransfercmd(cmd)
1840 self.busy = 1
1841
1842 ftpobj = addclosehook(conn.makefile('rb'), self.file_close)
1843 self.refcount += 1
1844 conn.close()
1845 # Pass back both a suitably decorated object and a retrieval length
1846 return (ftpobj, retrlen)
1847
1848 def endtransfer(self):
1849 if not self.busy:

Callers 1

ftp_openMethod · 0.45

Calls 11

endtransferMethod · 0.95
initMethod · 0.95
URLErrorClass · 0.90
addclosehookClass · 0.90
strFunction · 0.85
voidcmdMethod · 0.80
pwdMethod · 0.80
ntransfercmdMethod · 0.45
cwdMethod · 0.45
makefileMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected