How to sync (download) only files by extension

Hello,

Currently i’m working on a project that downloads .jpg from google cloud service(no google drive), then i have another file from that jpg and i sync that file back on server.

Is there a way to sync only .jpg files to my machine and to sync back on server everything from folder on my pc?

Cheers

Hi @dus.marjanovic,
You can use some CLI scripting to sync only files of a certain type. For example, you can create a script to list and sync only files with a .jpg.cloud extension. I can provide more details if this is something you are interested in doing.

Here is a blog post that provides some information on odrive CLI scripting: https://medium.odrive.com/sync-client-magic-602d858731de

Hello Tony, thanks for reply. I was trying to install and not sure where i make mistake.

Is there any video tutorial, i have struggles to get this to work.

I was expecting when i download file, that it will be like dos or power shell and i type these commands, but when i press on icon, nothing happens.

Can you help me about that part, please.

cheers

Hi @dus.marjanovic,
Here are some instructions for getting the CLI to work:

To use the CLI commands from Mac:

  1. Open a terminal session (type “terminal” in Spotlight search):

  2. Copy and paste the following command into the terminal and hit enter:
    exec 6>&1;num_procs=2;output="go"; while [ "$output" ]; do output=$(find "[folder to sync here]" -type f \( -name "*.cloudf" -o -name "*.jpg.cloud" \) -print0 | xargs -0 -n 1 -P $num_procs python $(ls -d "$HOME/.odrive/bin/"*/ | tail -1)odrive.py sync | tee /dev/fd/6); done

This will recursively download all .jpg files in the specified folder using 2 threads. You would need to change [folder to sync here] with the path to the folder you want to sync.



To use the CLI commands on Windows:

Open up a command prompt by clicking on the Windows icon in the taskbar, typing “cmd”, and then clicking on “Command Prompt”.

Once the command prompt is open, copy and paste the following command in (all one line) and hit enter. This will install the CLI for us to use in the next command. It could take a minute or two to complete. You only need to run this once on your machine:

powershell -command "& {$comm_bin=\"$HOME\.odrive\common\bin\";$o_cli_bin=\"$comm_bin\odrive.exe\";(New-Object System.Net.WebClient).DownloadFile(\"https://dl.odrive.com/odrivecli-win\", \"$comm_bin\oc.zip\");$shl=new-object -com shell.application; $shl.namespace(\"$comm_bin\").copyhere($shl.namespace(\"$comm_bin\oc.zip\").items(),0x10);del \"$comm_bin\oc.zip\";}"

This second command will do the download of jpg files:

powershell -command "& {$syncpath=\"[folder to sync here]\";$syncbin=\"$HOME\.odrive\common\bin\odrive.exe\";while ((Get-ChildItem $syncpath -Include *.cloudf, *.jpg.cloud -Recurse | Measure-Object).Count){Get-ChildItem -Path \"$syncpath\" -Include *.cloudf, *.jpg.cloud -Recurse | % { & \"$syncbin\" \"sync\" \"$($_.FullName)\";}}}"

This will recursively download all .jpg files in the specified folder. You would need to change [folder to sync here] with the path to the folder you want to sync.

Thanks for reply but it is not working for me.
Let me tell you my issue so you might have right answer for me. I have Google Cloud Storage (not google drive) and i have to unsync and sync every 5 minutes so my files are updated (it has to be like that).

So, since there is no autosync for google cloud storage, sync and unsync works in odrive.
Is it possible to do unsync/sync operation by time interval in cmd or somehow? I’m doing it now with software which move my mouse and do same what i did first time, it repeats and that is doing on every 5 mintues.

And i want to save from storage only .jpg. I don’t have that good programming background, but some stuff here is not straight forward, like [folder to sync here] …should my string to be inside of this brackets, or without, should be just path to odrive or google cloud storage?

my locations is C:\Users\dusma\odrive\Google Cloud Storage\

How can i call command? Should every time drag and drop C:\Users\dusma.odrive-agent\bin\odrive.exe to the powershell and then to copy your command?

I was looking on website for help, but everything is a bit confusing and not enough explained in my opinion. It ask me for placeholder…what is placeholder? and things like that.

Thanks

Hi @dus.marjanovic,
Can you explain your use case a bit more and why you need to unsync and sync every 5 minutes?

If you just want to make sure remote changes/updates are seen you can issue a refresh ( refresh command on the CLI) every 5 minutes on a folder to ask Google Cloud for changes within that folder. Refresh is not recursive, so you would need to perform refresh on each folder you want to force an update for.

Auto-unsync will work for all integrations, since it is a client-side thing and doesn’t have a dependency on the storage type. The shortest interval you can set is 1 day, though.

The command for your path to sync only *.jgp files would be:
powershell -command "& {$syncpath=\"C:\Users\dusma\odrive\Google Cloud Storage\";$syncbin=\"$HOME\.odrive\common\bin\odrive.exe\";while ((Get-ChildItem $syncpath -Include *.cloudf, *.jpg.cloud -Recurse | Measure-Object).Count){Get-ChildItem -Path \"$syncpath\" -Include *.cloudf, *.jpg.cloud -Recurse | % { & \"$syncbin\" \"sync\" \"$($_.FullName)\";}}}"

You just need to copy and paste that into the command prompt to sync all jpg files in the Google Cloud folder.

Take a look at the documentation here for information on placeholder folders and files: https://www.odrive.com/usageguide#placeholderfolders

Hi Tony,

I will explain why I need to be properly refreshed and why I want to download only .jpg

I made an app for android that uploads .jpg file for each user. Structure is Google Cloud Storage > username_folder > this folder contain uploaded .jpg file and .xml files.
Idea is to download .jpg files only (I don’t need .xml to be downloaded ), my computer process those .jpg, delete .jpg and create .xml in same folder where .jpg was, which will be uploaded to server back.

I have everything working for now, but I have to unsync and sync agan, so all files are updated.
It starts to be a problem since users created around 50 .jpg (which is now 50 .xml) which is deleted and not sync back, and instead of .jpg i create .xml and folders starts to be heavy.

That means if I sync every 5 minutes (needs to be like that) I need to download around 40MB of data, which is still all right, but since my app is growing this will start to be unmanageable and expensive.

I was reading cli, it look like that there might be option for that, but i can’t do it. Based on code that you provided, it seems that it will work to refresh photos that are already synced, not for new one.

Refresh and Sync is not working without firstly to do Unsync.
I discovered that if I enter to some folder, it somehow refresh content inside and it works.

So, i can’t believe that you guys are aware of this problem and there is no under the hood action in every 5 minutes system on your pc to enter every folder in storage so it is forced to refresh or to check which file type to sync somewhere in the options, this is my feedback. I am paying 100$ just to have folder which is updating itself every 24 hours. I can do that by myself.

I hope that this cli thing can help to make this to work.

Cheers

Hi @dus.marjanovic,
Having odrive default to refreshing every 5 minutes would create too much churn and overhead. We don’t have the ability to query Google Cloud storage for a delta (changes since the last check), so we need to pull the full listing of each “folder” to know what the content looks like. Doing this for all folders every 5 minutes would actually be impossible unless the data set was really small, as it would take longer than 5 minutes to do a full scan.

Using the CLI, it should be possible this way with a script that runs periodically:

  1. Issue a CLI refresh command on the desired folders to pick up any changes, both local and remote. This refresh should pick up all changes, not just ones to existing files.
  2. Sync any new jpg.cloud files that have shown up.
  3. Process your jpg files: create the xml files and delete the jpg files
  4. Issue another CLI refresh in the folder to make sure the local changes are picked-up by the sync engine and the new xml files are uploaded.
  5. Empty the odrive trash with the CLI emptytrash command, to sync the deletes of the jpg files to the remote storage.