要么需要安排定期的频繁工作,即连接和下载更改。
或者您需要持续运行流程,以保持连接打开并定期监视变化。
几乎没有更好的解决方案(这仍然是快速和容易实施)。使用WinSCP .NET assembly实现连续过程的
例子:
// Setup session options
SessionOptions sessionOptions = new SessionOptions {
Protocol = Protocol.Sftp,
HostName = "example.com",
UserName = "user",
Password = "mypassword",
SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
while (true)
{
// Download changes
session.Synchronize(
SynchronizationMode.Local, localPath, remotePath, false).Check();
// Wait 10 seconds
Thread.Sleep(10000);
}
}
您将需要添加一个更好的错误处理和重新连接,如果连接中断。
如果您不想将此作为(C#)应用程序实现,则可以使用PowerShell脚本。将上面的代码转换为PowerShell相当简单。 见
https://winscp.net/eng/docs/library_powershell
https://winscp.net/eng/docs/library_session_synchronizedirectories#powershell
是的,我需要一个汽车无正在运行的进程,保持打开的连接,并定期手表的变化。最好用SSH。 – Meethi 2014-10-29 09:13:45
@Meethi我在答案中增加了一些示例。 – 2014-10-29 09:40:25
谢谢!这就是我所寻找的。稍后我会发布我的解决方案。 – Meethi 2014-10-30 14:10:23