Exemplo n.º 1
0
        public string getCookieDestinet(string sUrl)
        {
            string destinet = "";
            var httpDownload = new HttpSession();

            var sPost = "dnn$ctr$Signin$Signin_textboxUsername=host" +
                        "&dnn$ctr$Signin$Signin_textboxPassword=guidedes10no" +
                        "&dnn$ctr$Signin$cmdLogin=Logg%20inn";

            var sContent = httpDownload.GetMethodDownload(sUrl, true, false, false, true);

            // step 2
            var _cookies = httpDownload.Cookies;

            string strRegex = "<input\\s+type=.{1}hidden.{1}\\s+name=.{1}__VIEWSTATE.{1}\\s+id=.{1}__VIEWSTATE.{1}\\s+value=.{1}([^.\"]+)";

            Regex rxGetViewState = new Regex(strRegex);
            Match mViewState = rxGetViewState.Match(sContent);

            string sViewState = mViewState.Groups[1].Value;//.Replace("/", "%2F").Replace("=", "%3D");
            sPost += "&__VIEWSTATE=" + sViewState;
            httpDownload.PostMethodDownload(sUrl, sPost, true, false, false, true);
            destinet = httpDownload.Cookies[".DESTINET"].Value;
            return destinet;
        }
Exemplo n.º 2
0
        public string getCookieDestinet(string sUrl1, ref CookieCollection _cookies)
        {
            string destinet = "";
            var httpDownload = new HttpSession();

            var sPost = "dnn$ctr$Signin$Signin_textboxUsername=host" +
                        "&dnn$ctr$Signin$Signin_textboxPassword=guidedes10no" +
                        "&dnn$ctr$Signin$cmdLogin=Logg%20inn";

            var sContent = httpDownload.GetMethodDownload(sUrl1, true, false, false, true);

            // step 2
            _cookies = httpDownload.Cookies;

            string strRegex = "<input\\s+type=.{1}hidden.{1}\\s+name=.{1}__VIEWSTATE.{1}\\s+id=.{1}__VIEWSTATE.{1}\\s+value=.{1}([^.\"]+)";
            Regex rxGetViewState = new Regex(strRegex);
            Match mViewState = rxGetViewState.Match(sContent);

            string sViewState = mViewState.Groups[1].Value;//.Replace("/", "%2F").Replace("=", "%3D");
            sPost += "&__VIEWSTATE=" + sViewState;
            httpDownload.PostMethodDownload(sUrl1, sPost, true, false, false, true);

            if (httpDownload.Cookies[".DESTINET"] != null)
            {
                destinet = httpDownload.Cookies[".DESTINET"].Value;
            }
            else
            {
                if (txtCookie.Text != "")
                {
                    Cookie c1 = new Cookie(".DESTINET", txtCookie.Text);
                    c1.Domain = sUrl.Replace("http://", "");
                    c1.Expired = false;
                    c1.Expires = DateTime.Now.AddMinutes(100);
                    httpDownload.Cookies.Add(c1);
                }
            }

            _cookies = httpDownload.Cookies;
            return destinet;
        }
Exemplo n.º 3
0
        public void downloadFile(ref HttpSession httpDownload, string ckLink)
        {
            var rootXML = httpDownload.GetMethodDownload(ckLink, true, false, false, true);

            if (!rootXML.Contains("<Connector><Error number=\"116\" /></Connector>"))
            {
                try
                {
                    XmlDocument _doc = new XmlDocument();
                    _doc.LoadXml(rootXML);
                    string rootFolderName = _doc.GetElementsByTagName("CurrentFolder")[0].Attributes[0].Value;
                    string fullFolderName = _doc.GetElementsByTagName("CurrentFolder")[0].Attributes[1].Value;
                    XmlNodeList listFile = _doc.GetElementsByTagName("File");
                    StreamWriter sw = new StreamWriter(targetFolder + rootFolderName + rootFolderName.Replace("/", "") + ".txt");

                    for (int _i = 0; _i < listFile.Count; ++_i)
                    {
                        try
                        {
                            if (listFile[_i].Attributes[0] != null)
                            {
                                string filename = listFile[_i].Attributes[0].Value;
                                if (filename.Contains("Cache"))
                                {
                                    int a = 3;
                                }
                                txtStatus.Text = "download file: " + System.Environment.NewLine +
                                  sUrl + fullFolderName + filename + System.Environment.NewLine + txtStatus.Text + System.Environment.NewLine;
                                sw.WriteLine(sUrl + fullFolderName + filename);
                                Application.DoEvents();
                                if (checkOnlyGetLink.Checked == false)
                                {
                                    if (!System.IO.File.Exists(targetFolder + rootFolderName + filename))
                                    {
                                        if (checkUseIDM.Checked == true)
                                        {
                                            if (rootFolderName.Length > 1)
                                            {
                                                downloadByIDM(sUrl + fullFolderName + filename, targetFolder + rootFolderName.Substring(0, rootFolderName.Length - 1));
                                            }
                                            else
                                            {
                                                downloadByIDM(sUrl + fullFolderName + filename, targetFolder);
                                            }
                                            Thread.Sleep(1000);
                                        }
                                        else
                                        {
                                            WebClient webClient = new WebClient();
                                            webClient.DownloadFile(sUrl + fullFolderName + filename, targetFolder + rootFolderName + filename);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            txtStatus.Text = ex.Message + System.Environment.NewLine + txtStatus.Text + System.Environment.NewLine;
                            Application.DoEvents();
                        }
                    }
                    sw.Close();
                }
                catch (Exception ex)
                {
                    string error = ex.Message;
                }
            }
        }
Exemplo n.º 4
0
        public void DownloadRecusive(ref HttpSession httpDownload, string ckLink, string parentFolder)
        {
            var rootXML = httpDownload.GetMethodDownload(ckLink, true, false, false, true);
            XmlDocument _doc = new XmlDocument();
            _doc.LoadXml(rootXML);
            string rootFolderName = _doc.GetElementsByTagName("CurrentFolder")[0].Attributes[0].Value;
            XmlNodeList listFolder = _doc.GetElementsByTagName("Folder");
            //download file for current folder
            string ckGetFileLink = sUrl + ckLoadLink.Replace("[[0]]", "GetFiles").Replace("[[1]]", "Portalens%20rotmappe").Replace("[[2]]", parentFolder.Replace("&", "%26"));
            downloadFile(ref httpDownload, ckGetFileLink);

            //get folders
            for (int _i = 0; _i < listFolder.Count; ++_i)
            {
                string FolderName = listFolder[_i].Attributes[0].Value;
                WebClient webClient = new WebClient();
                DirectoryInfo dir = new DirectoryInfo(targetFolder + parentFolder.Replace("%2F", "/") + FolderName);
                if (!dir.Exists)
                {
                    dir.Create();
                }
                bool hasChild = false;
                hasChild = bool.Parse(listFolder[_i].Attributes[1].Value);

                if (hasChild)
                {
                    string tempCKForderLink = sUrl + ckLoadLink.Replace("[[0]]", "GetFolders").Replace("[[1]]", "Portalens%20rotmappe").Replace("[[2]]", parentFolder + FolderName.Replace(" ", "%20").Replace("&", "%26") + "%2F");
                    DownloadRecusive(ref httpDownload, tempCKForderLink, parentFolder + FolderName + "%2F");
                }
                else
                {
                    //download file for current forder if it has not child
                    string ckGetFileLink1 = sUrl + ckLoadLink.Replace("[[0]]", "GetFiles").Replace("[[1]]", "Portalens%20rotmappe").Replace("[[2]]", parentFolder + FolderName.Replace("&", "%26") + "%2F");
                    downloadFile(ref httpDownload, ckGetFileLink1);
                }
            }
        }