コード例 #1
0
        ////private static string srv = "WIN";
        ////private static string login = "******";
        ////private static string parol = "temp2";
        ////private static string fpath = $@"smb://{login}:{parol}@{srv}/temp/";
        ////private static string targetf = @"C:\temp\";

        static void Main(string[] args)
        {
            SharpCifs.Config.SetProperty("jcifs.smb.client.responseTimeout", "3000");
            SharpCifs.Config.SetProperty("jcifs.smb.client.connTimeout", "3000");
            SharpCifs.Config.SetProperty("jcifs.smb.client.soTimeout", "3000");

            //using System;
            //using SharpCifs.Smb;

            //Get SmbFile-Object of a folder.


            //UnixTime
            var epocDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            while (true)
            {
                var folder = new SmbFile(fpath);
                try
                {
                    folder.ListFiles();
                    Thread.Sleep(1000);
                }
                catch (Exception e)
                {
                    try
                    {
                        for (int i = 0; i <= 3; i++)
                        {
                            SmbTransport.ClearCachedConnections(true);
                            break;
                        }
                    }
                    catch (Exception exception)
                    {
                        Thread.Sleep(1000);
                    }
                    Console.WriteLine(e);
                }
                continue;

                //List items
                foreach (SmbFile item in folder.ListFiles())
                {
                    var lastModDate = epocDate.AddMilliseconds(item.LastModified())
                                      .ToLocalTime();

                    var name = item.GetName();
                    var type = item.IsDirectory() ? "dir" : "file";
                    var date = lastModDate.ToString("yyyy-MM-dd HH:mm:ss");
                    var msg  = $"{name} ({type}) - LastMod: {date}";


                    // GetFile(item);
                    Console.WriteLine(msg);
                }
            }

            Console.ReadLine();
        }
コード例 #2
0
 private static void ClearSmbState()
 {
     try
     {
         SmbTransport.ClearCachedConnections(true);
         SmbFile.Initialize();
     }
     catch { }
 }
コード例 #3
0
 public void Reset()
 {
     try
     {
         for (int i = 0; i <= 3; i++)
         {
             SmbTransport.ClearCachedConnections(true);
             break;
         }
     }
     catch (Exception)
     {
         Thread.Sleep(1000);
     }
 }