-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathftpy.py
41 lines (37 loc) · 1.09 KB
/
ftpy.py
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
# -*- coding: utf-8 -*-
"""
from pitchmuc
"""
from ftplib import FTP
### example
host = 'myhost.com'
username = "username"
password="password"
_version='1.0.0'
def seeFile(host,user,mdp):
with FTP(host) as ftp:
ftp.login(user,mdp)
print(ftp.nlst())
return ftp.nlst()
def retrieveFileFTP(host,filename,user,mdp):
fileName= filename
localfile=open(filename, 'wb')
with FTP(host) as ftp:
ftp.login(user,mdp)
print(ftp.dir())
ftp.retrbinary('RETR '+fileName,localfile.write,262144)
localfile.close()
def deleteFileFTP(host,filename,user,mdp):
fileName=filename
with FTP(host) as ftp:
ftp.login(user,mdp)
ftp.delete(fileName)
def sendFile(host,filename,user,mdp):
fileName=filename
with FTP(host) as ftp:
ftp.login(user,mdp)
ftp.storlines('STOR '+fileName,open(fileName,'rb'))
seeFile(host,username,password)## print the file in the console
retrieveFileFTP('somefile.txt',host,username,password)
sendFile('somefile.txt',host,username,password)
deleteFileFTP('somefile.txt',host,username,password)