cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Not happy with your Spotify Wrapped? Check out how Kevin on the Dropbox team used Paper to make sure he keeps discovering new music over here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
1
Ask
2
Reply and help

API Copy/Sync two folders in dropbox account

API Copy/Sync two folders in dropbox account

GFunk
Explorer | Level 3

I have a simple requirement that I'm really struggling to get working.

 

We need to sync up several (100+) directories with their subdirectories (all under the same account). For eg:

 

Source\Dir1\A1\file1.pdf

Source\Dir1\A2\file2.pdf

 

And copy to Dest\Dir1\A1\file1.pdf etc...

 

This works easily via the API if the dest directory doesn't exist:

 

 try {
                    $dropbox->copy($dropboxFolder$destPath);
                } catch (\Exception $e) {
                    $this->copyFolderOnDropboxByFile($dropboxFolder$destPath);
                }

 

However, if it does, it seems I have to go any copy file by file, and then the process becomes EXTREMELY slow and often times out (perhaps running afoul of the API performance limits)

 

We run this process every 5 mins to make sure we are snycing up any straggling files. How can I efficiently run this ONLY when we are sure there are files that have changed/need to be synced?

 

Note: I can't simply delete the dest dir and recopy because there are people who are syncing these dirs to their local Dropbox account and that causes a massive amount of churning. (There could be 100dirs and 5000 files in the extreme case).

 

I'm using the PHP API in Laravel but what I'm after is the *correct* way of doing this. If I coudl simply compare last folder modified date or something simple, I could then only recopy folders that have changed. 

 

What can you suggest?

1 Reply 1

Re: API Copy/Sync two folders in dropbox account

Greg-DB
Dropboxer

I recommend reading the "Detecting Changes Guide" here:

 

https://www.dropbox.com/lp/developers/reference/detecting-changes-guide

 

That covers the options for efficiently detecting and listing just the changes that have occurred since you last checked, e.g., using the "cursor" functionality on /2/files/list_folder[/continue]. For cases where you can't just copy the folder in its entirety, you could use that to determine what specific items need to be copied.

 

Also, for the actual copying, when you have multiple items to copy, you can use the /2/files/copy_batch_v2 endpoint to do so in bulk:

 

https://www.dropbox.com/developers/documentation/http/documentation#files-copy_batch

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?