创建一个与远程位置连接的文件夹,例如 Dropbox
我怎样才能制作一个可以做事情的文件夹。当然,Dropbox 知道文件何时放入文件夹,并且该文件已同步。我怎样才能创建一个具有相同功能的文件夹,并且将我放入其中的文件发送到我的 ftp?
我正在尝试在 Mac 上执行此操作(当然,Dropbox 在 Mac 上运行良好)。
How can I make a folder that does things. Surely dropbox knows when a file is put in the folder, and that file is synced. How can I make a folder that does the same, and that the files I put in it go to my ftp?
I'm trying to do this on a Mac (surely, Dropbox works fine on a Mac).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您正在寻找的是一种监视文件何时更改的方法。然后,您可以像您提到的那样通过 FTP 上传更改的文件。如果是这种情况,答案是与 Windows 文件夹和文件事件相关联。这是一篇关于如何执行此操作的好文章:
http://www.codeproject.com/ KB/files/MonitorFolderActivity.aspx
可以在此处找到 FTP 文件所需的代码:
http://msdn.microsoft.com/en-us/library/ms229715.aspx
所有这些都假设您将使用 C#。如果您要使用不同的语言,则需要以相同的基本方式执行相同的基本操作,但语法会有所不同。
要开始使用,这就是您所需要的。您观察文件夹中任何文件的更改。当您看到更改时,您可以通过 FTP(如果这是您想要的网络传输方法)将更改的文件上传到远程位置。当然,您需要为其他客户做相反的事情。他们需要订阅您服务器上的事件,告诉他们下载已更改文件的最新版本。最后,您需要应用自己的业务逻辑来处理诸如您希望上传发生的频率、是否要为更改启用日志记录、是否要进行文件版本控制等事情。
I believe what you are looking for is a way to monitor when files are changed. Then, you can simply upload the changed file via FTP like you mentioned. If this is the case, the answer is to tie into the Windows Folder and File events. Here is a good article on how to do so:
http://www.codeproject.com/KB/files/MonitorFolderActivity.aspx
The code needed to FTP a file can be found here:
http://msdn.microsoft.com/en-us/library/ms229715.aspx
All of this is assuming you are going to be using C#. If you are going to use a different language, you will need to perform the same basic actions in the same basic manner but the syntax will be different.
To get started, this is all you need. You watch the folder for changes to any of the files. When you see a change, you upload the changed file via FTP (if that is your desired method of web transport) to the remote location. Of course, you would need to do the opposite for other clients. They would need to subscribe to events on your server that told them to download the latest versions of the changed files. Finally, you would need to apply your own business logic for things like how often you want the uploads to happen, if you want logging enabled for the changes, if you are going to do file versioning, etc.
一种解决方案(仅限 Windows + .NET)是运行客户端并使用 FileSystemWatcher 并且当更改事件触发时,执行与 FTP 同步所需的适当操作。
One solution(windows only + .NET) would be to run a client with and monitor a folder with FileSystemWatcher and when the change event fires, do appropriate action required to sync with FTP.