Tools, FAQ, Tutorials:
Sending FTP Request with urllib.request.urlopen
How to send an FTP request with the urllib.request.urlopen() function?
✍: FYIcenter.com
If an FTP server supports anonymous access, you can send an FTP request to retrieve a directory list, or download a file using the urllib.request.urlopen() function:
Here is a Python example on how to get a directory list from an anonymous FTP server:
>>> import urllib >>> url='ftp://space.mit.edu/pub/' >>> r = urllib.request.urlopen(url) >>> b = r.read() >>> print(b) b'drwxrwxr-x 6 ftpuser ftpusers 512 Jun 27 2012 ASC\r\n lrwxrwxrwx 1 ftpuser ftpusers 3 Nov 20 2011 CXC -> ASC\r\n drwx------ 2 ftpuser ftpusers 512 May 2 2016 OLD\r\n ...
Here is a Python example on how to download a file from an anonymous FTP server:
>>> import urllib >>> url='ftp://space.mit.edu/pub/cgrant/cti_temp.txt' >>> r = urllib.request.urlopen(url) >>> b = r.read() >>> print(b) >>> b' 2000.0801 -119.870 2000.0804 -119.870 2000.0857 -119.810 2000.0860 -119.700 2000.0874 -119.810 2000.0877 -119.850 2000.0930 -119.700 2000.0932 -119.630 ...
⇒ 'requests' Module - HTTP for Humans
⇐ urllib.request.Request Properties and Functions
2023-10-06, 4774🔥, 1💬
Popular Posts:
How to pull NVIDIA CUDA Docker Image with the "docker image pull nvidia/cuda" command? If you are ru...
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...
How to use "{{...}}" Liquid Codes in "set-body" Policy Statement? The "{{...}}" Liquid Codes in "set...
How to use the "Ctrl-p Ctrl-q" sequence to detach console from the TTY terminal of container's runni...
How to view API details on the Publisher Dashboard of an Azure API Management Service? You can follo...