C# 如何在远距离观看文件夹

C# 如何在远距离观看文件夹,c#,ftp,filesystemwatcher,C#,Ftp,Filesystemwatcher,我可以在本地观看文件夹,但如何在远距离观看文件夹 我使用以下代码: private void Do_Automatic() { FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = Properties.Settings.Default.Chemin; /* Watch for changes in LastAccess and LastWrite times, and th

我可以在本地观看文件夹,但如何在远距离观看文件夹

我使用以下代码:

private void Do_Automatic()
{
    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.Path = Properties.Settings.Default.Chemin; 
    /* Watch for changes in LastAccess and LastWrite times, and
       the renaming of files or directories. */
    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
       | NotifyFilters.FileName | NotifyFilters.DirectoryName;
    // Only watch text files.
    watcher.Filter = Properties.Settings.Default.Type_Fichier;

    // Add event handlers.
    //watcher.Changed += new FileSystemEventHandler(OnChanged);
    watcher.Created += new FileSystemEventHandler(OnChanged);          


    // Begin watching.
    watcher.EnableRaisingEvents = true;

    // Wait for the user to quit the program.
    //Console.WriteLine("Press \'q\' to quit the sample.");
    //while (Console.Read() != 'q') ;
}

// Define the event handlers. 
private  void OnChanged(object source, FileSystemEventArgs e)
{                     
    //MessageBox.Show("File: " + e.FullPath + " " + e.ChangeType);
    var fi = new FileInfo(e.FullPath);
    if (Isaccesible(fi, FileMode.Open, FileAccess.Read)) { DoSaveNPrint(); }

}

bool Isaccesible(FileInfo fi, FileMode Fmode, FileAccess Facces)
{
    bool hasAcces = false;
    while (!hasAcces)
    {
        try
        {
            using (var filestrem = File.Open(fi.FullName, Fmode, Facces))
            { }
            hasAcces = true;
        }
        catch (IOException ex)
        { 
         //absorb exexpteion and try again
            Thread.Sleep(600);
        }
        catch (Exception)
        {

            throw;
        }
    }
    return true;
}

private  void DoSaveNPrint()
{
   //download the file
} 
在距离平均值上,在其他服务器上

我的服务器-互联网-其他服务器

现在,我通过FTP导入文件,如下所示:

 public void Put_FromFTP(string ClientID, string filename)
        {
            try
            {
                FtpWebRequest reqFTP;
                try
                {
                    Get_ListFileFTPExtracted(ClientID);
                    //filePath = <<The full path where the file is to be created.>>, 
                    //fileName = <<Name of the file to be created(Need not be the name of the file on FTP server).>>

                    FileStream outputStream = new FileStream(Path.Combine(filePath, filename), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

                    //Other
                    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + ftpChemin + "//" + filename));



                    reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
                    reqFTP.UseBinary = true;
                    reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                    FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                    Stream ftpStream = response.GetResponseStream();
                    long cl = response.ContentLength;
                    int bufferSize = 2048;
                    int readCount;
                    byte[] buffer = new byte[bufferSize];

                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                    while (readCount > 0)
                    {
                        outputStream.Write(buffer, 0, readCount);
                        readCount = ftpStream.Read(buffer, 0, bufferSize);
                    }

                    ftpStream.Close();
                    outputStream.Close();
                    response.Close();


                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
            catch (Exception excThrown)
            {
                throw new Exception("Err_Sauvgarder fichier -->" + filename + excThrown.Message, excThrown);
            }
        }

它最多可支撑10英尺,无需进一步支撑。你说的距离是什么意思?您可以使用UNC路径。如果要在远程计算机上查看文件,则需要通过UNC路径访问该文件。除此之外,它与本地文件几乎相同。不,FileSystemWatcher不能通过FTP工作。你能给我一个例子吗,我像这个watcher一样尝试过。Path=@\xxx.xxx.xxx.xxx\PC NAME\IIS Folder\Folder\;不工作。