-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
executable file
·57 lines (40 loc) · 1.28 KB
/
script.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
# -*- encondig: utf-8 -*-
from ftplib import FTP
from datetime import datetime
import env, os, logging
now = datetime.now().strftime("%d-%m-%Y %H:%M:%S")
logging.basicConfig(filename=env.LOG, filemode='a', level=logging.DEBUG)
try:
print 'Starting FTP Connection'
ftp = FTP()
ftp.connect(env.URL, env.PORT)
ftp.login(env.USER, env.PASSD)
f = open(env.FILE, 'rb')
ftp.cwd(env.PATH)
try:
print "Uploading file from %s to %s:%s" % (env.FILE, env.URL, env.PATH)
ftp.storlines('STOR ' + env.FILENAME, f)
if env.REMOVE:
os.remove(env.FILE)
print "Erasing %s..." % env.FILE
print """
Transference Successfull
Process Completed
"""
msj = 'Uploaded file Successful at %s in %s' % (now, env.PATH)
logging.info(msj)
except Exception, e:
print str(e)
logging.warning('ERROR: %s %s' % (str(e), now))
except Exception, e:
logging.warning(str(e))
msj = 'FTP transferetion failed. File %s was not upload at %s' % (env.FILE, now)
logging.warning(msj)
print """
Opps something is wrong:
%s. Check the %s
""" % (str(e), env.LOG)
finally:
ftp.quit()
ftp.close()