문제

The problem is easy:

>>> urllib.urlretrieve('ftp://maia.usno.navy.mil/ser7/tai-utc.dat', 'tai-utc.dat')
...
IOError: [Errno ftp error] [Errno ftp error] 502 Command not implemented: PASV

Apparently urllib uses ftplib in default mode which means passive mode, which is blocked by the corporate firewall. And ftplib isn't clever enough to try active mode if passive fails.

Using wget:

$ wget ftp://maia.usno.navy.mil/ser7/tai-utc.dat
--2014-02-19 11:26:31--  ftp://maia.usno.navy.mil/ser7/tai-utc.dat
           => `tai-utc.dat'
Resolving maia.usno.navy.mil (maia.usno.navy.mil)... 199.211.133.23
Connecting to maia.usno.navy.mil (maia.usno.navy.mil)|199.211.133.23|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /ser7 ... done.
==> SIZE tai-utc.dat ... 3159
==> PASV ... 
Cannot initiate PASV transfer.
==> PORT ... done.    ==> RETR tai-utc.dat ... done.
Length: 3159 (3.1K) (unauthoritative)

100%[==================================================================================================>] 3,159       --.-K/s   in 0s      

2014-02-19 11:26:32 (211 MB/s) - `tai-utc.dat' saved [3159]

How can I use active mode with urllib? If it's impossible, what are my options?

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top