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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
# -*- coding: iso-8859-1 -*-
from ftplib import *
from tkinter import *
class Graphique:
def __init__(self):
#instanciation d'un nouvel objet de ClientFtp
client=ClientFtp("ftpperso.free.fr","xxxxx","xxxxx")
self.root = Tk()
self.root.configure(height="500", width="500", bg='#548754')
self.can = Canvas(self.root, height="200", width="300", bg="ivory")
btnQuitter = Button(self.root, text="Quitter", command=self.root.destroy).pack()
btnConnect = Button(self.can, text="connexion", command=client.connexion).pack()
btnDeconnect = Button(self.can, text="deconnexion", command=client.deconnexion).pack()
btnAffiche = Button(self.can, text="afficher", command=client.afficherContenu(self.root)).pack()
Message(self.can, text=client.rep).pack()
#on place une liste pour afficher les repertoire
self.can.pack()
self.root.mainloop()
class ClientFtp:
def __init__(self,host,user,password):
self.host = host
self.port = "21"
self.user = user
self.password = password
self.etatConnexion="0"
self.rep=""
def connexion(self):
try:
self.ftp = FTP(self.host, self.user, self.password)
self.etat="connecté"
print('Etat:',self.etat)
self.etatConnexion="1"
except:
self.etat="non connecté"
print('Etat:',self.etat)
def afficherContenu(self,fenetre):
if self.etatConnexion=="1":
self.rep=self.ftp.dir()
Message(fenetre, text=self.rep).pack()
else:
print("on n'est pas connecté")
def deconnexion(self):
try:
self.ftp.quit
self.etat="non connecté"
print('Etat:',self.etat)
except:
print('Etat:',self.etat)
if __name__ == "__main__":
Graphique() |
Partager