public void MakeDirectory(ref Content Files, ref DataUser User, ListView ListFiles, TextBox NewFolder, string Folder) { Rename Active = new Rename(); if (Active.CheckName(Folder, Files)) { if (User.CheckIntConnect()) { ReqRes Act = new ReqRes(); try { HttpWebRequest Request = Act.MakeRequest(User.Data.UrlServer, User.Data.Hrefs.Last() + Folder, User.Data.Name, User.Data.Password); if (Request != null) { Request.Method = WebRequestMethods.Http.MkCol; Act.GetResponse(Request); User.InfoFiles(ref Files, ref User, ref ListFiles, User.Data.Hrefs.Last(), true); NewFolder.Text = ""; } } catch (WebException ex) { if (GotMessage != null) { GotMessage(ex.Message); } } } } }
private void Delete(object it) { if (InterUser.CheckIntConnect()) { int index = (int)it; if (InterFiles.All[index].Href != InterUser.Data.Hrefs.Last()) { ReqRes Act = new ReqRes(); try { HttpWebRequest Request = Act.MakeRequest(InterUser.Data.UrlServer, InterFiles.All[index].Href, InterUser.Data.Name, InterUser.Data.Password); Request.Method = "DELETE"; Act.GetResponse(Request); } catch (WebException ex) { if (GotMessage != null) { GotMessage(ex.Message); } } } } handle.Set(); }
public bool MakeNewName(DataUser User, int Item, string Name, Content Files) { if (User.CheckIntConnect()) { ReqRes Act = new ReqRes(); try { HttpWebRequest Request = Act.MakeRequest(User.Data.UrlServer, Files.All[Item].Href, User.Data.Name, User.Data.Password); Request.Method = "MOVE"; Request.Accept = "*/*"; string NewName = User.Data.Hrefs.Last() + Name; if (Files.All[Item].ContentType == "d:collection") { NewName += "/"; } Request.Headers.Add("Destination: " + HttpUtility.UrlPathEncode(NewName)); Act.GetResponse(Request); return(true); } catch (WebException ex) { if (GotMessage != null) { GotMessage(ex.Message); } return(false); } } return(false); }
private void Upload(object it) { if (InterUser.CheckIntConnect()) { int index = (int)it; ReqRes Act = new ReqRes(); try { HttpWebRequest Request = Act.MakeRequest(InterUser.Data.UrlServer, InterUser.Data.Hrefs.Last() + SafeNames[index], InterUser.Data.Name, InterUser.Data.Password); FileStream ReadStream = new FileStream(Names[index], FileMode.Open, FileAccess.Read); Request.Method = WebRequestMethods.Http.Put; Request.ContentLength = ReadStream.Length; Request.KeepAlive = false; Request.ReadWriteTimeout = -1; Request.Timeout = -1; Request.AllowWriteStreamBuffering = true; Request.PreAuthenticate = false; Request.SendChunked = false; Request.ContentType = "application/binary"; Request.ProtocolVersion = HttpVersion.Version11; Request.ServicePoint.ConnectionLimit = 1; Request.AllowAutoRedirect = false; Request.ServicePoint.Expect100Continue = true; Request.Accept = "*/*"; Stream reqStream = Request.GetRequestStream(); if (reqStream != null) { byte[] inData = new byte[8192]; int bytesRead = ReadStream.Read(inData, 0, inData.Length); while (bytesRead > 0) { reqStream.Write(inData, 0, bytesRead); bytesRead = ReadStream.Read(inData, 0, inData.Length); } ReadStream.Close(); reqStream.Close(); Act.GetResponse(Request); } } catch (WebException ex) { if (GotMessage != null) { GotMessage(ex.Message); } } } handle.Set(); }
public void InfoFiles(ref Content Files, ref DataUser User, ref ListView ListFiles, string Folder, bool forward) { if (User.CheckIntConnect()) { ReqRes Act = new ReqRes(); try { HttpWebRequest Request = Act.MakeRequest(User.Data.UrlServer, Folder, User.Data.Name, User.Data.Password); Request.Accept = "*/*"; Request.Headers.Add("Depth: 1"); Request.Method = "PROPFIND"; HttpWebResponse Response = Act.GetResponseStream(Request); Stream ResponseStream = Response.GetResponseStream(); Files.All.Clear(); ListFiles.Items.Clear(); Files.SetInfoContent(ResponseStream, ref Files.All, ref ListFiles); ResponseStream.Close(); Response.Close(); if (forward) { if (!User.Data.Hrefs.Contains(Folder)) { User.Data.Hrefs.Add(Folder); } } else { User.Data.Hrefs.RemoveAt(User.Data.Hrefs.Count - 1); } } catch (WebException ex) { if (GotMessage != null) { GotMessage(ex.Message); } } } else { if (GotMessage != null) { GotMessage("Вы не подключены к Интернету!"); } } }
private void Download(object it) { if (InterUser.CheckIntConnect()) { int index = (int)it; if (InterFiles.All[index].ContentType != "d:collection") { ReqRes Act = new ReqRes(); try { HttpWebRequest Request = Act.MakeRequest(InterUser.Data.UrlServer, InterFiles.All[index].Href, InterUser.Data.Name, InterUser.Data.Password); Request.Method = WebRequestMethods.Http.Get; HttpWebResponse Response = Act.GetResponseStream(Request); int byteTransferRate = 8192; byte[] bytes = new byte[byteTransferRate]; int bytesRead = 0; long totalBytesRead = 0; Directory.CreateDirectory("./Download/"); long contentLength = long.Parse(Response.GetResponseHeader("Content-Length")); Stream NewStream = Response.GetResponseStream(); FileStream NewFileStream = new FileStream("./Download/" + InterFiles.All[index].DisplayName, FileMode.Create, FileAccess.Write); do { bytesRead = NewStream.Read(bytes, 0, bytes.Length); if (bytesRead > 0) { totalBytesRead += bytesRead; NewFileStream.Write(bytes, 0, bytesRead); } }while (bytesRead > 0); NewStream.Close(); NewFileStream.Close(); Response.Close(); } catch (WebException ex) { if (GotMessage != null) { GotMessage(ex.Message); } } } } handle.Set(); }
private void Connection(string UserName, string Password) { DataUser User = new DataUser(); if (User.CheckIntConnect()) { ReqRes Act = new ReqRes(); string UrlServer = "https://webdav.yandex.ru"; HttpWebRequest Request = Act.MakeRequest(UrlServer, "", UserName, Password); if (Request != null) { Request.Accept = "*/*"; Request.Headers.Add("Depth: 1"); Request.Method = "PROPFIND"; Act.GetResponse(Request); { MainForm Main = new MainForm(UrlServer, UserName, Password, this); Main.Show(); this.Hide(); } } } }
private void Paste(object it) { if (InterUser.CheckIntConnect()) { int index = (int)it; ReqRes Act = new ReqRes(); try { HttpWebRequest Request = Act.MakeRequest(InterUser.Data.UrlServer, InterFiles.CopyHref[index], InterUser.Data.Name, InterUser.Data.Password); Request.Method = "COPY"; Request.Accept = "*/*"; Request.Headers.Add("Destination: " + HttpUtility.UrlPathEncode(InterUser.Data.Hrefs.Last() + InterFiles.CopyName[index])); Act.GetResponse(Request); } catch (WebException ex) { if (GotMessage != null) { GotMessage(ex.Message); } } } handle.Set(); }