1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| REP_COURANT= chemin_export
try:
#connexion au serveur FTP
connect=ftplib.FTP('machin')
connect.login('machin')
connect.cwd('machin/machin')
donnee = []
connect.retrlines('NLST', donnee.append) # liste des fichiers du FTP
# suppression du fichier précedent
for fic in donnee:
if (fic.startswith("T")and fic.endswith("prv")):
connect.delete(fic)
print("Suppression de " + fic)
# transfert vers ftp du fichier
for f in os.listdir(REP_COURANT):
if (f.startswith("T") and f.endswith("prv")):
file = open(os.path.join(REP_COURANT,f),'rb')
connect.storbinary('STOR '+f, file)
print('Transfert sur FTP de ' + f)
file.close()
connect.quit()
except:
print("Erreur TRANSFERT FTP")
for f in os.listdir(REP_COURANT):
if (f.startswith("T")):
os.remove(REP_COURANT + "/" + f) |
Partager