Download our e-book of Introduction To Python
Neha Kumawat
3 years ago
import ftplib
ftp = ftplib.FTP("ftp.nluug.nl")
ftp.login("anonymous", "ftplib-example-1")
data = []
ftp.dir(data.append)
ftp.quit()
for line in data:
print("-", line)
- lrwxrwxrwx 1 0 0 1 Nov 13 2012 ftp -> .
- lrwxrwxrwx 1 0 0 3 Nov 13 2012 mirror -> pub
- drwxr-xr-x 23 0 0 4096 Nov 27 2017 pub
- drwxr-sr-x 88 0 450 4096 May 04 19:30 site
- drwxr-xr-x 9 0 0 4096 Jan 23 2014 vol
import ftplib
ftp = ftplib.FTP("ftp.nluug.nl")
ftp.login("anonymous", "ftplib-example-1")
data = []
ftp.cwd('/pub/') #change directory to /pub/
ftp.dir(data.append)
ftp.quit()
for line in data:
print("-", line)
- lrwxrwxrwx 1 504 450 14 Nov 02 2007 FreeBSD -> os/BSD/FreeBSD
- lrwxrwxrwx 1 504 450 20 Nov 02 2007 ImageMagick -> graphics/ImageMagick
- lrwxrwxrwx 1 504 450 13 Nov 02 2007 NetBSD -> os/BSD/NetBSD
- lrwxrwxrwx 1 504 450 14 Nov 02 2007 OpenBSD -> os/BSD/OpenBSD
- -rw-rw-r-- 1 504 450 932 Jan 04 2015 README.nluug
- -rw-r--r-- 1 504 450 2023 May 03 2005 WhereToFindWhat.txt
- drwxr-sr-x 2 0 450 4096 Jan 26 2008 av
- drwxrwsr-x 2 0 450 4096 Aug 12 2004 comp
import ftplib
import sys
def getFile(ftp, filename):
try:
ftp.retrbinary("RETR " + filename ,open(filename, 'wb').write)
except:
print "Error"
ftp = ftplib.FTP("ftp.nluug.nl")
ftp.login("anonymous", "ftplib-example-1")
ftp.cwd('/pub/') #change directory to /pub/
getFile(ftp,'README.nluug')
ftp.quit()