从 Web 服务器持续同步更改 [英] Continuously sync changes from web server
问题描述
我正在寻找一种方法来将我的文件从 Web 服务器 (Ubuntu 14) 同步(任务)到本地服务器(Windows Server).Web 服务器创建本地服务器需要的小文件.Web 服务器位于 DMZ 中,可通过 SSH 访问.只有本地服务器才能访问 Web 服务器上的文件夹.它尝试使用像 WinSCP 这样的程序,但我无法设置get"-Job.
有没有办法在 Windows 服务器上使用 SSH 做到这一点,而无需每隔几秒登录一次?或者有更好的解决方案吗?未来网络服务是可能的,但目前我需要一个快速的解决方案.
或者你需要安排一个经常性的工作,连接和下载变化.
或者您需要持续运行进程,以保持连接打开并定期监视更改.
几乎没有更好的解决方案(这仍然快速且易于实施).
使用WinSCP .NET程序集实现的连续过程示例:
//设置会话选项SessionOptions sessionOptions = 新的 SessionOptions {协议 = 协议.Sftp,主机名 = "example.com",用户名 = "用户",密码 = 我的密码",SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...=";};使用(会话会话 = 新会话()){//连接session.Open(sessionOptions);而(真){//下载更改session.SynchronizeDirectories(SynchronizationMode.Local, localPath, remotePath, false).Check();//等待 10 秒线程睡眠(10000);}}
如果连接中断,您将需要添加更好的错误处理和重新连接.
如果您不想将其实现为 (C#) 应用程序,您可以使用 PowerShell 脚本.有关完整解决方案,请参阅保持本地目录最新(从远程 SFTP/FTP 服务器下载更改的文件)..>
I'm searching for a way to get my Files synchronized (task) from a web server (Ubuntu 14) to a local server (Windows Server). The web server creates small files, which the local Server needs. The web server is in a DMZ, accessible through SSH. Only the local server is able to access folders on web server. It tried using Programs like WinSCP, but I'm not able to set a "get"-Job.
Is there a way to do this with SSH on Windows server without login every few seconds? Or is there a better solution? In the Future Web-Services are possible, but at the moment I need a quick solution.
Either you need to schedule a regular frequent job, that connects and downloads changes.
Or you need to have continuously running process, that keeps the connection opened and regularly watches for changes.
There's hardly a better solution (that's still quick and easy to implement).
Example of continuous process implemented using WinSCP .NET assembly:
// Setup session options
SessionOptions sessionOptions = new SessionOptions {
Protocol = Protocol.Sftp,
HostName = "example.com",
UserName = "user",
Password = "mypassword",
SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...="
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
while (true)
{
// Download changes
session.SynchronizeDirectories(
SynchronizationMode.Local, localPath, remotePath, false).Check();
// Wait 10 seconds
Thread.Sleep(10000);
}
}
You will need to add a better error handling and reconnect, if connection breaks.
If you do not want to implement this as (C#) application, you can use PowerShell script. For a complete solution, see Keep local directory up to date (download changed files from remote SFTP/FTP server).
这篇关于从 Web 服务器持续同步更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!