-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathovh_upload.py
66 lines (48 loc) · 1.45 KB
/
ovh_upload.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
58
59
60
61
62
63
64
65
66
from pathlib import Path
import os
import ftplib
import getpass
try:
jwa_dir = Path(__file__).parent
os.chdir(jwa_dir)
except NameError:
jwa_dir = Path(os.getcwd())
site_dir = jwa_dir.joinpath('_site')
ftp = ftplib.FTP('ftp.cluster027.hosting.ovh.net')
ftp.login('jwaclassxd', getpass.getpass())
##
ftp.rmd('www')
ftp.mkd('www')
##
def FtpRmTree(ftp, path):
"""Recursively delete a directory tree on a remote server."""
wd = ftp.pwd()
try:
names = ftp.nlst(path)
except ftplib.all_errors as e:
# some FTP servers complain when you try and list non-existent paths
_log.debug('FtpRmTree: Could not remove {0}: {1}'.format(path, e))
return
for name in names:
if os.path.split(name)[1] in ('.', '..'): continue
_log.debug('FtpRmTree: Checking {0}'.format(name))
try:
ftp.cwd(name) # if we can cwd to it, it's a folder
ftp.cwd(wd) # don't try a nuke a folder we're in
FtpRmTree(ftp, name)
except ftplib.all_errors:
ftp.delete(name)
try:
ftp.rmd(path)
except ftplib.all_errors as e:
_log.debug('FtpRmTree: Could not remove {0}: {1}'.format(path, e))
for obj in sorted(site_dir.rglob('*')):
print(obj)
rel_path = obj.relative_to(site_dir)
if obj.is_dir():
print(obj)
else:
print("STOR", rel_path)
ftp.storbinary('STOR ' + obj.name, open(str(obj), 'rb'))
##
ftp.quit()