Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload / download folders #182

Open
helenhuangmath opened this issue Oct 19, 2021 · 7 comments
Open

upload / download folders #182

helenhuangmath opened this issue Oct 19, 2021 · 7 comments

Comments

@helenhuangmath
Copy link

helenhuangmath commented Oct 19, 2021

Hi dropbox team,
Does dbxcli support folder uploading or downloading now? What command should I use for folder operation? Thank you!

@conphi
Copy link

conphi commented Jan 16, 2022

dbxcli ls -l "path/to/folder/to/download"|awk -F"ago" '{print $2}'|sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'|xargs -I{} dbxcli get {} .

@lumosideas
Copy link

dbxcli ls -l "path/to/folder/to/download"|awk -F"ago" '{print $2}'|sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'|xargs -I{} dbxcli get {} .

Hi, this command is to download a directory, what about upload put a full directory to dropbox?

Thank you

@lpares12
Copy link

@lumosideas did you manage to do it?

@lumosideas
Copy link

Hi, no, I have not receive answers to my question so I decide to use this script:

https://github.com/andreafabrizi/Dropbox-Uploader

However, I'm looking forward for an answer here.

@tashrifbillah
Copy link

dbxcli ls -l "path/to/folder/to/download"|awk -F"ago" '{print $2}'|sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'|xargs -I{} dbxcli get {} .

This command won't work for two-level deep folders.
cc @conphi

@jmgirard
Copy link

jmgirard commented Feb 4, 2024

In case anyone wants to adapt this to Powershell on windows:

./dbxcli ls -l "/path/to/folder/to/download" | ForEach-Object { $_ -split 'ago' | Select-Object -Index 1 } | ForEach-Object { $_.Trim() } | ForEach-Object { ./dbxcli get $_ . }
  1. Lists files in the specified directory using ./dbxcli ls -l.
  2. For each line of the output, splits the line at the string 'ago' and selects the second part (Select-Object -Index 1).
  3. Trims leading and trailing whitespaces from each result.
  4. Calls ./dbxcli get for each result.

@gprabaha
Copy link

gprabaha commented Feb 20, 2024

Dropbox does not let you compress and download large files through the web browser, and the desktop client cannot be used practically to sync up with an external hard drive. I recently had to write a bash script using dbxcli which downloads directories and subdirectories and recreates the directory structure locally. Seemed relevant to this conversation

#!/bin/bash

# Function to create a directory if it doesn't exist
ensure_directory() {
  local path="$1"
  if [ ! -d "$path" ]; then
    mkdir -p "$path"
  fi
}

# Function to download files and replicate directory structure
download_files() {
  local path="$1"
  local destination="$2"
  local top_name="${path##*/}"
  local local_dest_path="$destination/$top_name"
  local depth="$3"
  local tabs=""
  for ((i=0; i<depth; i++)); do
    tabs+="    "
  done

  # Check if the item is not a file (does not contain a dot in the filename)
  if [[ "$path" != *.* ]]; then
    ensure_directory "$local_dest_path"
    echo -e "${tabs}Folder: $top_name"

    # Get the total number of items in the directory without leading whitespaces
    local total_items=$(dbxcli ls -l "$path" 2>/dev/null | awk 'NR>1 {print $NF}' | wc -l | awk '{$1=$1};1')
    local current_item=1
    tabs+="    "
    # Iterate over items in the directory
    dbxcli ls -l "$path" | awk 'NR>1 {print $NF}' | while read -r item; do
      local local_name="${item##*/}"
      echo -e "${tabs}Item $current_item of $total_items"
      local new_depth=$((depth+1))
      download_files "$item" "$local_dest_path" "$new_depth"
      ((current_item++))
    done
  else
    # If it's a file (contains a dot), use dbxcli get (output silenced)
    echo -e "${tabs}Downloading: $top_name"
    dbxcli get "$path" "$local_dest_path" > /dev/null 2>&1
  fi
}

# Download files and replicate directory structure
download_files "$1" "$2" "$3"

echo "Download completed."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants