Changes I make locally are quickly synched, but changes made to the remote SFTP folder sometimes take hours to sync to the local folder, and I often have to open my local folder and hit refresh to nudge it to sync. I need it to be able to sync quickly, even when the PC is locked. Does anyone have any ideas?
Sources like Dropbox and Google Drive have an API that can be called to request recent changes. odrive will do this frequently to be notified of what has changed on the remote server and then can react to those changes quickly. For SFTP, there isn’t a way to ask for changes. This means odrive has to request a listing for every folder to know when the contents have changed.
Because this can be extremely expensive, depending on the number of folders you are syncing and what storage you have linked, odrive only does this a couple of times a day (it will also do it when it starts-up). As you noted above, odrive will also request a listing of the folder when you browse into it via Finder/Explorer from another location, if you perform a right-click->refresh, or if a local changed is detected (a file is added or changed locally in that folder).
If you are up for it, you can use our CLI to write a basic script that you can run periodically to force a scan for changes. In the case of your SFTP server, you are probably not going to run into server-side restrictions (or retaliation…) for makings lots of frequent calls. Let me know and we can work on an example of that.
Hi Tony. Thanks for your reply. It makes sense that you limit calls to the SFTP server for most people. I only have about 10 folders, each of which have maybe 0 to 1 subfolder. If you have some example code I could look at that would be great. I’ll see what I can with your CLI.
I’ve put a sample script which you can use here in our documentation:
It’s powershell only right now. Are you on Windows or Mac/Linux? Let us know if this is enough for you to move forward with.
You should be able to just copy-and-paste the contents into a new .ps1 file, change the $REFRESHPATH variable setting, and then run it on a machine where you’ve already installed the odrive windows desktop client.
Thanks Jeff. I can get the code to work in powershell, but I am not able to schedule it as in here. I know the code works, so it must be an issue with the scheduler. I tried changing the path to the ps from %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe to C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe but that did not work either. So I don’t know what the issue is?
Also, the guidance states that to run more than once an hour you need to create multiple tasks, but can’t we just click Advanced Settings -> Repeat task every: [5 minutes]?
Yes, you’re right regarding the “Repeat task ever: [5 minutes]” thing–the docs have been updated to reflect that info. Thanks!
Regarding the instructions, I tried the steps again and was able to get it to work. Every 5 minutes, I see a powershell window open and the refresh script output appears. After the script executes, the powershell window closes.
It sounds like you’ve already made sure the script runs fine via executing it in powershell directly.
The actions tab lets you browse to find the executable, so you could try that to find powershell.exe (just to eliminate any possibilities with this being a problem). Make sure under Add arguments field you’ve specified a valid path to your script, too.
One other area you can check is to open the Windows Event Viewer and then go to the left pane and expand Applications and Services Logs… then click on Windows PowerShell to see if there’s any additional information there.
Is there any information or a screenshot that you can provide to show what’s not working? Or is it just not doing anything?
And one more thing to try… you can redirect output streams (everything, including warning and error streams) to a file to see if there’s any other info added there.
To do this, go back to the Actions tab of the Task Scheduler. Doublecheck the Program/script points to powershell.exe and then under the Add arguments (optional) section, you can specify both the path to the script and an output file as follows.
The code works when I enter it directly into PS. I followed the troubleshooting guide and used PS to run the saved script and it returned this error: PS C:\Program Files> .\Refresh_ODrive.ps1
.\Refresh_ODrive.ps1 : File C:\Program Files\Refresh_ODrive.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170
So it looks like an issue with my execution polices. Do you know how I can adjust them so it runs?
I tried adding an output to a log in Add Arguments: C:\Program Files\Refresh_ODrive.ps1 *> C:\Program Files\refresh.log but there was no output to the log, I guess because it’s not running.
In the Task Scheduler, the Last Run Result is (0x1)
Thanks for providing all of the detailed info. Yeah, it does seem like it is the execution policy…
There are ways to change your policy or get around it, such as the info in this article outlines. Sometimes these settings are dictated by group policies in active directory (if you are on a corporate machine) and so forth, so if you are on a work computer, I would consult your company’s IT admin.
If you’re on a personal machine, you can try this:
Right-click on powershell in your windows toolbar and select to Run as Administrator.
Run Get-ExecutionPolicy -List at the powershell prompt to show what your execution policies are… on the machine I’m on, all my policies are set to “Undefined” except for my “LocalMachine” scope… I’m betting that if you could set the “LocalMachine” scope to either “Unrestricted” or “Bypass” then things could work for you. (You can click here to learn more about Microsoft’s execution policy parameters).
Run this command: Set-ExecutionPolicy Unrestricted -Scope LocalMachine
So you would see something like this:
PS C:\WINDOWS\system32> Set-ExecutionPolicy Unrestricted -Scope LocalMachine
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y
PS C:\WINDOWS\system32> Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Unrestricted
After doing this, you could give it a shot.
Alternatively, try one of the 15 methods in the article mentioned earlier. I’d say be careful setting the policy to something you’re comfortable with. You can go over the article and try to find a way to do it without setting your policy as a whole if you’d like. For instance, item #3 (example 2) may work where you can set up a batch script which invokes the powershell script… so your task scheduler would point to that batch script instead.
Changing the execution policy is more like a safety speedbump and less of a real security measure to keep malicious scripts from running, if that is any consolation… most malware that you would have to be afraid of would run circles around this (especially considering there’s articles like “15 Ways to Bypass the PowerShell Execution Policy”). But I will leave that up to you to make your informed decision.
I thought it was working but I deleted some files about 4 hours ago and it had not deleted them locally when I checked just now.
My execution policies are as above:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Unrestricted
so I don’t know what the issue could be. Could you add an option for users to set the sync timings for people like me with a small number of files that need to be kept in regular sync? You could add a warning that changing the setting is only for specific cases like mine.
Were you redirecting output to a log file (ODrive not reliably syncing with STFP folder) by chance? If so, can you go to the log file and check the timestamp on it? And also look in it and see if there are any errors?
I’m just curious if it’s a matter of:
Script didn’t run
Script ran but didn’t work
I tested the script again by deleting some files on my remote SFTP storage and running it. When it syncs, it definitely removes the files on local correctly for me. So right now I’m wondering if it just didn’t run for some reason. Also, how often do you have it configured to run currently?
Regarding the setting to set sync timings, thanks for the feedback. I’ve noted it and will chat with the product team guys about the possibility. It would be simultaneously useful and dangerous. =)
Thanks,
-Jeff
P.S. One other thing that can help in the meantime is to create a shortcut to your .ps1 file and put it somewhere or pin it to your windows task bar so you can run it on demand whenever you need to if you think there are any remote changes that haven’t been detected yet. This is a convenience bandaid, of course… I’d like to see if we can figure out what’s going on with the more automatic setup.
Hi @ians75,
I wanted to let you know that we released a new version today that includes an advanced feature to modify the remote scan interval, which will dictate the frequency that odrive scans the remote storage. This feature should be used with caution because it can be expensive, as stated above, but it may be helpful for you.
New version information here: Desktop Release (02-11-2021) Win v.6879 / Mac v.6984