ftp.py
· 782 B · Python
Raw
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import ftplib
host = 'ftp.redhat.com'
username = 'anonymous'
password = 'xxx@gmail.com'
with ftplib.FTP(host, username, password) as ftp :
print('Entrée à la racine du ftp')
ftp.dir()
DIR='./redhat/linux/beta/SAM/SRPMS'
print('Déplacement dans le répertoire "%s"'%DIR)
ftp.cwd(DIR)
ftp.dir()
FILE='thumbslug-deps-0.0.8-1.el6.src.rpm'
print('Téléchargement du fichier %s'%FILE)
print("%s : "%FILE, end="")
def ecrire(data):
print(".", end="")
fp.write(data)
with open(FILE, 'wb') as fp:
ftp.retrbinary('RETR %s'%FILE, ecrire)
#ftp.retrbinary('RETR %s'%FILE, fp.write)
print()
# fin de session | pas necessaire grace au with
#ftp.quit()
| 1 | #!/usr/bin/python3 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| 4 | import ftplib |
| 5 | |
| 6 | host = 'ftp.redhat.com' |
| 7 | username = 'anonymous' |
| 8 | password = 'xxx@gmail.com' |
| 9 | |
| 10 | with ftplib.FTP(host, username, password) as ftp : |
| 11 | print('Entrée à la racine du ftp') |
| 12 | ftp.dir() |
| 13 | DIR='./redhat/linux/beta/SAM/SRPMS' |
| 14 | print('Déplacement dans le répertoire "%s"'%DIR) |
| 15 | ftp.cwd(DIR) |
| 16 | ftp.dir() |
| 17 | FILE='thumbslug-deps-0.0.8-1.el6.src.rpm' |
| 18 | print('Téléchargement du fichier %s'%FILE) |
| 19 | print("%s : "%FILE, end="") |
| 20 | def ecrire(data): |
| 21 | print(".", end="") |
| 22 | fp.write(data) |
| 23 | with open(FILE, 'wb') as fp: |
| 24 | ftp.retrbinary('RETR %s'%FILE, ecrire) |
| 25 | #ftp.retrbinary('RETR %s'%FILE, fp.write) |
| 26 | print() |
| 27 | # fin de session | pas necessaire grace au with |
| 28 | #ftp.quit() |