-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathftpupload.py
More file actions
35 lines (22 loc) · 743 Bytes
/
ftpupload.py
File metadata and controls
35 lines (22 loc) · 743 Bytes
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
#!/usr/bin/env micropython
# -*- coding: utf-8 -*-
def split(path):
if path == "":
return ("", "")
r = path.rstrip("/").rsplit("/", 1)
if len(r) == 1:
return ("", path)
return (r[0] or "/", r[1])
def basename(path):
return split(path)[1]
def upload(ftp, path, remote_path=None, blocksize=8192, callback=None,
rest=None):
if remote_path:
remote_dir, remote_path = split(remote_path)
if remote_dir:
ftp.cwd(remote_dir)
if not remote_path:
remote_path = basename(path)
with open(path, 'rb') as fp:
return ftp.storbinary('STOR %s' % remote_path, fp, blocksize=blocksize,
callback=callback, rest=rest)