要麼需要安排定期的頻繁工作,即連接和下載更改。
或者您需要持續運行流程,以保持連接打開並定期監視變化。
幾乎沒有更好的解決方案(這仍然是快速和容易實施)。使用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