-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_FTP.py
More file actions
39 lines (37 loc) · 1.11 KB
/
class_FTP.py
File metadata and controls
39 lines (37 loc) · 1.11 KB
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
#!/usr/bin/python
# -*- coding: utf-8 -*
from ftplib import *
class ftpManager():
"""
Gestion FTP
"""
def __init__(self, host, login, password):
"""Connection au serveur FTP"""
self.ftp = FTP(host, login, password)
def list(self):
"""Afficher le contenu du dossier"""
self.ftp.dir()
def cp(self, lpath, rpath):
"""
Copier un fichier
- lpath = Chemin local
- rpath = Chemin distant
"""
self.upfile = open(lpath, "rb")
self.upname = rpath
self.ftp.storlines("STOR " + self.upname, self.upfile)
def ren(self, oldname, newname):
"""Renommer dossier"""
self.ftp.rename(oldname, newname)
def mkdir(self, name):
"""Créer un dossier"""
self.ftp.mkd(name)
def rmdir(self, name):
"""Supprimer un dossier"""
self.ftp.rmd(name)
def rm(self, name):
"""Supprimer un fichier"""
self.ftp.delete(name)
def cd(self, name):
"""Changer de dossier"""
self.ftp.connect.sendcmd('CWD '+ name)