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
|
"""
Upload a file to a server (or other filesystem)
Usage:
python upload.py FILENAME <FS URL>
example:
python upload.py foo.txt ftp://example.org/uploads/
"""
import sys
import os
from fs import open_fs
_, file_path, fs_url = sys.argv
filename = os.path.basename(file_path)
with open_fs(fs_url) as fs:
if fs.exists(filename):
print("destination exists! aborting.")
else:
with open(file_path, "rb") as bin_file:
fs.upload(filename, bin_file)
print("upload successful!")
|