示例#1
0
        public override Server creack(string ip, int port, string username, string password, int timeOut)
        {
            Server server = new Server();

            try
            {
                if ("".Equals("空"))
                {
                    password = "";
                }
                UniAddress ud = UniAddress.GetByName(ip);
                NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(ip, username, password);
                SmbConstants.DefaultConnTimeout     = timeOut * 1000;
                SmbConstants.DefaultResponseTimeout = timeOut * 1000;
                SmbConstants.DefaultSoTimeout       = timeOut * 1000;
                SmbSession.Logon(ud, port, auth);//验证是否能够成功登录
                server.isSuccess = true;
            }
            catch (SmbAuthException fe)
            {
                server.isSuccess = false;
            }
            catch (Exception e)
            {
                throw e;
            }
            return(server);
        }
示例#2
0
 /// <exception cref="SharpCifs.Smb.SmbAuthException"></exception>
 public virtual Hashtable GetTrustedDomains(NtlmPasswordAuthentication auth)
 {
     if (Disabled || auth.Domain == "?")
     {
         return(null);
     }
     if (Domains != null && Runtime.CurrentTimeMillis() > Domains.Expiration)
     {
         Domains = null;
     }
     if (Domains != null)
     {
         return(Domains.Map);
     }
     try
     {
         UniAddress   addr  = UniAddress.GetByName(auth.Domain, true);
         SmbTransport trans = SmbTransport.GetSmbTransport(addr, 0);
         CacheEntry   entry = new CacheEntry(Ttl * 10L);
         DfsReferral  dr    = trans.GetDfsReferrals(auth, string.Empty, 0);
         if (dr != null)
         {
             DfsReferral start = dr;
             do
             {
                 string domain = dr.Server.ToLower();
                 entry.Map.Put(domain, new Hashtable());
                 dr = dr.Next;
             }while (dr != start);
             Domains = entry;
             return(Domains.Map);
         }
     }
     catch (IOException ioe)
     {
         if (Log.Level >= 3)
         {
             Runtime.PrintStackTrace(ioe, Log);
         }
         if (StrictView && ioe is SmbAuthException)
         {
             throw (SmbAuthException)ioe;
         }
     }
     return(null);
 }
示例#3
0
 /// <exception cref="SharpCifs.Smb.SmbAuthException"></exception>
 public virtual SmbTransport GetDc(string domain, NtlmPasswordAuthentication auth)
 {
     if (Disabled)
     {
         return(null);
     }
     try
     {
         UniAddress   addr  = UniAddress.GetByName(domain, true);
         SmbTransport trans = SmbTransport.GetSmbTransport(addr, 0);
         DfsReferral  dr    = trans.GetDfsReferrals(auth, "\\" + domain, 1);
         if (dr != null)
         {
             DfsReferral start = dr;
             IOException e     = null;
             do
             {
                 try
                 {
                     addr = UniAddress.GetByName(dr.Server);
                     return(SmbTransport.GetSmbTransport(addr, 0));
                 }
                 catch (IOException ioe)
                 {
                     e = ioe;
                 }
                 dr = dr.Next;
             }while (dr != start);
             throw e;
         }
     }
     catch (IOException ioe)
     {
         if (Log.Level >= 3)
         {
             Runtime.PrintStackTrace(ioe, Log);
         }
         if (StrictView && ioe is SmbAuthException)
         {
             throw (SmbAuthException)ioe;
         }
     }
     return(null);
 }
 // This is NOT best-practice code, just showing a demo Jcifs api call
 public async Task getFileContents2()
 {
     await Task.Run(() => {
         var lan = new SmbFile("smb://", NtlmPasswordAuthentication.Anonymous);
         // var workgroups = lan.ListFiles();
         UniAddress u  = UniAddress.GetByName("ALEXEY-PC");
         Button button = FindViewById <Button>(Resource.Id.myButton);
         RunOnUiThread(() => {
             button.Text = u.ToString();
         });
     }
                    ).ContinueWith((Task arg) => {
         Console.WriteLine(arg.Status);
         if (arg.Status == TaskStatus.Faulted)
         {
             Console.WriteLine(arg.Exception);
         }
     }
                                   );
 }