javascript 用于可以同步文件的 Node.js 的 FTP 模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11114890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FTP module for Node.js that can sync files?
提问by mzedeler
I am looking for a module for Node.js - preferably available through npm that can sync files with an FTP server. The ftp module has all the basic functions, but writing a full blown sync system on top of it seems like a lot of work.
我正在寻找 Node.js 的模块 - 最好通过 npm 提供,它可以与 FTP 服务器同步文件。ftp 模块具有所有基本功能,但在其上编写完整的同步系统似乎需要大量工作。
回答by Sergi Mansilla
I'm the author of jsftp. It should be easy to sync through it simply walking through the directories you want to upload. Jsftp can handle parallel passive requests (internally they are still sequential, but you don't have to worry about it), so you could just use sequential ftp.put
calls and it should work without much scripting effort on your side.
我是jsftp的作者。只需遍历您要上传的目录,就可以轻松地通过它进行同步。Jsftp 可以处理并行的被动请求(在内部它们仍然是顺序的,但您不必担心),因此您可以只使用顺序ftp.put
调用,它应该可以在您不需要太多脚本工作的情况下工作。
Even better and more idiomatic in node would be to use the yet to be documented ftp.getPutSocket
method, which allows you to get the raw PASV
socket and just push into it (using streams, for example). For a particular example of this case, you can look at how vfs-ftpdoes it.
在 node 中更好和更惯用的方法是使用尚未记录的ftp.getPutSocket
方法,它允许您获取原始PASV
套接字并直接推入它(例如,使用流)。对于这种情况的特定示例,您可以查看vfs-ftp是如何做到的。
Feel free to contact me if you need more help with implementing the syncing.
如果您在实现同步方面需要更多帮助,请随时与我联系。
回答by jsalonen
I did some research by searching npm, github and the web and couldn't come across any good looking solution to syncing.
我通过搜索 npm、github 和网络进行了一些研究,但找不到任何好看的同步解决方案。
I would simply start by writing my own (simple) synchronization lib by using some good ftp library. Personally I find jsftp to be the most appealing (http://sergi.github.com/jsftp/). Just combine jsftp with some filesystem walking - especially if you are fine with simple one-way syncing, this shouldn't be impossible to do.
我会简单地通过使用一些好的 ftp 库来编写我自己的(简单的)同步库。我个人认为 jsftp 是最吸引人的(http://sergi.github.com/jsftp/)。只需将 jsftp 与一些文件系统遍历结合起来 - 特别是如果你对简单的单向同步没问题,这应该是不可能的。
Some ideas for implementing (one-way sync from local filesystem to ftp):
实现的一些想法(从本地文件系统到 ftp 的单向同步):
- Open connection to the ftp server
- Walk through local filesystem with
fs.readdir
- Get stats from the corresponding ftp file and upload if local version is newer (
Ftp.ls
andFtp.put
if usingjsftp
)
- 打开与 ftp 服务器的连接
- 遍历本地文件系统
fs.readdir
- 从相应的FTP文件获取的统计信息和上传如果地方版本更新(
Ftp.ls
和Ftp.put
如果使用jsftp
)
Alternatively, ask yourself do you really need to perform the sync with node.js? For instance if you can run Python scripts in your system, you could simply use ftpsync2d
, a bidirectional sync tool with ftp support (http://code.google.com/p/ftpsync2d/).
或者,问问自己是否真的需要与 node.js 执行同步?例如,如果您可以在您的系统中运行 Python 脚本,您可以简单地使用ftpsync2d
,一个支持 ftp 的双向同步工具 ( http://code.google.com/p/ftpsync2d/)。
回答by Evan Plaice
Take a look at node-ftpsyncand grunt-ftpsync
看看node-ftpsync和grunt-ftpsync
It utilizes Sergi's jsftplibrary to intelligent sync files to a remote server.
它利用 Sergi 的jsftp库将文件智能同步到远程服务器。
Note: Currently, everything needed for push support is implemented except timestamp based update comparisons. For now updates are determined by comparing file sizes alone.
注意:目前,除了基于时间戳的更新比较之外,推送支持所需的一切都已实现。目前更新是通过单独比较文件大小来确定的。
node-ftpsyncprovides both CLI support and a programming API. The preferred solution is to install it globally and run it in a directory containing a config.json. Alternately, it is also implemented as a lib that can be easily configured, extended, and launched within code.
node-ftpsync提供 CLI 支持和编程 API。首选的解决方案是全局安装它并在包含 config.json 的目录中运行它。或者,它也可以作为一个库来实现,可以在代码中轻松配置、扩展和启动。
grunt-ftpsyncworks the same way except configuration and running the application is done through grunt. It can even outputs fancy colorized logs.
grunt-ftpsync 的工作方式相同,除了配置和运行应用程序是通过 grunt 完成的。它甚至可以输出花哨的彩色原木。
Disclaimer: I am the author of node-ftpsync and grunt-ftpsync
免责声明:我是 node-ftpsync 和 grunt-ftpsync 的作者