(self, file, type)
| 2425 | self.ftp.cwd(_target) |
| 2426 | |
| 2427 | def retrfile(self, file, type): |
| 2428 | import ftplib |
| 2429 | self.endtransfer() |
| 2430 | if type in ('d', 'D'): cmd = 'TYPE A'; isdir = 1 |
| 2431 | else: cmd = 'TYPE ' + type; isdir = 0 |
| 2432 | try: |
| 2433 | self.ftp.voidcmd(cmd) |
| 2434 | except ftplib.all_errors: |
| 2435 | self.init() |
| 2436 | self.ftp.voidcmd(cmd) |
| 2437 | conn = None |
| 2438 | if file and not isdir: |
| 2439 | # Try to retrieve as a file |
| 2440 | try: |
| 2441 | cmd = 'RETR ' + file |
| 2442 | conn, retrlen = self.ftp.ntransfercmd(cmd) |
| 2443 | except ftplib.error_perm as reason: |
| 2444 | if str(reason)[:3] != '550': |
| 2445 | raise URLError(f'ftp error: {reason}') from reason |
| 2446 | if not conn: |
| 2447 | # Set transfer mode to ASCII! |
| 2448 | self.ftp.voidcmd('TYPE A') |
| 2449 | # Try a directory listing. Verify that directory exists. |
| 2450 | if file: |
| 2451 | pwd = self.ftp.pwd() |
| 2452 | try: |
| 2453 | try: |
| 2454 | self.ftp.cwd(file) |
| 2455 | except ftplib.error_perm as reason: |
| 2456 | raise URLError('ftp error: %r' % reason) from reason |
| 2457 | finally: |
| 2458 | self.ftp.cwd(pwd) |
| 2459 | cmd = 'LIST ' + file |
| 2460 | else: |
| 2461 | cmd = 'LIST' |
| 2462 | conn, retrlen = self.ftp.ntransfercmd(cmd) |
| 2463 | self.busy = 1 |
| 2464 | |
| 2465 | ftpobj = addclosehook(conn.makefile('rb'), self.file_close) |
| 2466 | self.refcount += 1 |
| 2467 | conn.close() |
| 2468 | # Pass back both a suitably decorated object and a retrieval length |
| 2469 | return (ftpobj, retrlen) |
| 2470 | |
| 2471 | def endtransfer(self): |
| 2472 | if not self.busy: |
no test coverage detected