简体   繁体   English

比较本地文件和云文件(将Dropbox与DropNet lib结合使用)

[英]Compare local file and cloud file (using Dropbox with DropNet lib)

in C# I'm creating a client to sync local files and Dropbox folder, using DropNet lib. 在C#中,我正在创建一个客户端,以使用DropNet lib同步本地文件和Dropbox文件夹。
If the same file is present both in the cloud and in the local folders, how do I check if they are equivalent, or which of the two is more up to date? 如果在云和本地文件夹中都存在相同的文件,我如何检查它们是否等效,或者这两个文件中的哪个最新? If I compare the ModifiedDate of cloud file with LastWriteTime of local file, these dates are always conflicting, probably because the client time is different from the dropbox's server time. 如果将云文件的ModifiedDate与本地文件的LastWriteTime进行比较,则这些日期始终会发生冲突,这可能是因为客户端时间与保管箱的服务器时间不同。 How can I make a efficient file compare? 如何进行有效的文件比较?

The Dropbox API allows you to interface with the normal Dropbox ecosystem, and when syncing with Dropbox there may be well more than 2 clients on a single account. Dropbox API允许您与正常的Dropbox生态系统接口,并且与Dropbox同步时,单个帐户上可能有两个以上的客户端。 To reconcile this, the Dropbox servers are considered the source of truth. 为了解决这个问题,Dropbox服务器被认为是事实的来源。 So, when you're syncing with Dropbox, the intention is that you should get all changes from the server, as well as report all local changes to the server, as soon as possible. 因此,在与Dropbox同步时,目的是应该从服务器获取所有更改,并尽快将所有本地更改报告给服务器。

Along those lines, while the Dropbox API doesn't currently offer a way to get a file ID or hash for a remote file (though we're tacking this as a feature request) it does offer ways to know if files have changed remotely so that you can update your local state. 因此,尽管Dropbox API当前不提供获取远程文件的文件ID或哈希的方法(尽管我们将其作为功能请求),但它确实提供了方法来了解文件是否已远程更改。您可以更新本地状态。 One way to use the "rev" property of a file at a particular path via the /metadata API call: 通过/ metadata API调用在特定路径上使用文件的“ rev”属性的一种方法:

https://www.dropbox.com/developers/core/docs#metadata https://www.dropbox.com/developers/core/docs#metadata

If the rev has changed since you last checked it, the file at that path has changed. 如果自上次检查以来版本已更改,则该路径上的文件已更改。

Another way is to use /delta: 另一种方法是使用/ delta:

https://www.dropbox.com/developers/core/docs#delta https://www.dropbox.com/developers/core/docs#delta

You can occasionally call this to find out about any changes you need to make to your local state to get back up to date. 您有时可以调用此命令来查找需要对本地状态进行任何更改以恢复最新状态的信息。

A byte by byte comparison is probably the most correct approach. 逐字节比较可能是最正确的方法。 Read this link for a discussion on file hashes. 阅读此链接以获取有关文件哈希的讨论。

https://stackoverflow.com/a/7931320/1706610 https://stackoverflow.com/a/7931320/1706610

And here's a nice link for a byte by byte file comparison method. 这是一个逐字节文件比较方法的不错链接。

http://www.dotnetperls.com/file-equals http://www.dotnetperls.com/file-equals

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM