Last active
December 20, 2022 02:27
-
-
Save fcoclavero/13dca8264a4e9a530c5ca0e68642c7ae to your computer and use it in GitHub Desktop.
Dropbox cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fix Dropbox access denied Mac OS | |
sudo chflags -R nouchg ~/Dropbox ~/.dropbox ~/.dropbox-master | |
sudo chown "$USER" "$HOME" | |
sudo chown -R "$USER" ~/Dropbox ~/.dropbox | |
sudo chmod -RN ~/.dropbox ~/Dropbox | |
chmod -R u+rw ~/Dropbox ~/.dropbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sync - download | |
mkdir "local/directory" & for i in $(dbxcli ls -R "dropbox/directory"); do; dbxcli get $i "local/directory"/$(basename $i); done | |
# Sync - upload | |
find "local/directory" | while read file; do echo "$file"; target="dropbox/directory/"$file; ./dbxcli put "$file" "$target"; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read .dropbox ignore and recursively set selective sync options | |
# https://help.dropbox.com/en-us/files-folders/restore-delete/ignored-files | |
$ignoreList = Get-Content .dropboxignore | |
$folderList = Get-ChildItem -Path . -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName | |
$baseList=@() | |
"Ignoring the following folders:" | |
$ignoreList | |
"" | |
foreach ($folder in $folderList) | |
{ | |
foreach ($ignore in $ignoreList) | |
{ | |
$ignore = $ignore.Trim() | |
$index = $folder.FullName.IndexOf($ignore) | |
if ($index -ge 0 ) | |
{ | |
$base = $folder.FullName.SubString(0, $index+$ignore.Length) | |
if ( ! $baseList.Contains($base)) | |
{ | |
$base | |
Set-Content -Path "$base" -Stream com.dropbox.ignored -Value 1 | |
$baseList = $baseList + $base | |
} | |
break | |
} | |
} | |
} | |
"" | |
"Folders ignored:" | |
$baseList | |
# Clear-Content -Path 'C:\Users\yourname\Dropbox\ (Personal)/YourFileName.pdf' -Stream com.dropbox.ignored | |
# Set-Content -Path C:\Users\lars\Dropbox\RaiseYourFinger\node_modules -Stream com.dropbox.ignored -Value 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Wrap "dbxcli get" command to download files from a dropbox dir recursively | |
import os | |
import sys | |
import subprocess | |
import re | |
import argparse | |
import hashlib | |
args = None | |
def md5(f): | |
BLOCKSIZE=65536 | |
hasher = hashlib.md5() | |
with open(f, 'rb') as afile: | |
buf = afile.read(BLOCKSIZE) | |
while len(buf) > 0: | |
hasher.update(buf) | |
buf = afile.read(BLOCKSIZE) | |
return(hasher.hexdigest()) | |
def get(remote): | |
dlproc = subprocess.run(["dbxcli", "get", remote], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
if args.verbose: | |
try: | |
count, order = re.compile('/(\S+)\s(\S+)').match(dlproc.stderr.decode('utf-8')).group(1, 2) | |
print("Downloaded " + remote +" "+ count + " " + order) | |
except Exception: | |
print("Downloaded " + remote) | |
def getr(remote, local): | |
localcwd = os.getcwd() | |
os.chdir(local) | |
#print("cwd: " + os.getcwd()) | |
regex = re.compile('^(\S+).*/(.+?)\s*$') | |
proc = subprocess.run(["dbxcli", "ls", "-l", remote], stdout=subprocess.PIPE) | |
lines = proc.stdout.decode('utf-8').splitlines() | |
for line in lines[1:]: | |
obj_id, obj_name = regex.match(line).group(1, 2) | |
if obj_id == "-": | |
os.mkdir(obj_name) | |
if args.verbose: print("Created " + remote+'/'+obj_name) | |
getr(remote+'/'+obj_name, obj_name) | |
else: | |
if args.verify: | |
hash=None | |
while True: | |
get(remote+'/'+obj_name) | |
chash = md5(obj_name) | |
if hash == chash: | |
break | |
else: | |
hash=chash | |
else: | |
get(remote+'/'+obj_name) | |
os.chdir(localcwd) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-V', dest='verify', action='store_true', help='Verify downloads (download it several times)') | |
parser.add_argument('-v', dest='verbose', action='store_true', help='Be verbose') | |
parser.add_argument('remote', type=str, help='remote_dir') | |
parser.add_argument('local', type=str, help='local_dir') | |
args = parser.parse_args() | |
if args.remote is None or args.local is None: | |
parser.print_help() | |
sys.exit(-1) | |
getr(args.remote, args.local) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment