Continuously sync changes from web server

▼魔方 西西 提交于 2021-01-24 07:11:27

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/26582974/continuously-sync-changes-from-web-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!