简体   繁体   English

通过Windows应用程序检查远程文件夹上的文件

[英]Checking files on a remote folder through Windows app

I am using VS-2008 [C#] with .NET 3.5 SP1 installed. 我在安装NET 3.5 SP1的情况下使用VS-2008 [C#]。

I am writing an auto-update utility for my application. 我正在为我的应用程序编写一个自动更新实用程序。 I want to connect via FTP and search for the files on the remote server. 我想通过FTP连接并在远程服务器上搜索文件。 I want to check the versions of the local and remote file. 我想检查本地和远程文件的版本。 As expected, if new files are on server, display alert. 如预期的那样,如果服务器上有新文件,则显示警报。

I started with following code: 我从以下代码开始:

FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://ftp.mysite.com//myFiles");
try
{
    ftpRequest.Credentials = new NetworkCredential("new user", "new password");
    ftpRequest.Method = WebRequestMethods.Ftp.GetDateTimestamp;
    DateTime FtpFileLastModified = ((FtpWebResponse)ftpRequest.GetResponse()).LastModified;
}
catch (Exception)
{
    throw;
}  

I want to know which is a recommended method to perform this type of task in .NET 3.5 SP1 . 我想知道推荐使用哪种方法在.NET 3.5 SP1执行此类任务。 Please illustrate with a little code. 请用一些代码说明。

您可以使用FileSystemWatcher类-侦听文件系统更改通知,并在目录或目录中的文件更改时引发事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM