public static bool UploadFile(string localFilePath, string serverFolder) { bool b = false; System.Net.WebClient myWebClient = new System.Net.WebClient(); myWebClient.Credentials = System.Net.CredentialCache.DefaultCredentials; FileStream fs = new FileStream(localFilePath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); byte[] postArray = br.ReadBytes((int)fs.Length); Stream postStream = myWebClient.OpenWrite(serverFolder, "PUT"); if (postStream.CanWrite) { postStream.Write(postArray, 0, postArray.Length); b = true; } postStream.Close(); postStream.Dispose(); return b; } public static string Download(string uri, string savePath) { if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath); string fileName = string.Empty; if (uri.IndexOf(@"..\") > -1 || uri.IndexOf(@"\") > -1) { uri = uri.Replace(@"..\", "/"); uri = uri.Replace(@"\", "/"); } if (uri.IndexOf("\\") > -1) { fileName = uri.Substring(uri.LastIndexOf("\\") + 1); } else { fileName = uri.Substring(uri.LastIndexOf("/") + 1); } if (!savePath.EndsWith("/") && !savePath.EndsWith("\\")) { savePath = savePath + "/"; } WebClient client = new WebClient(); client.DownloadFile(uri, savePath); return savePath; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)