/// <summary> /// add information to upload a file, also perform check of file size and file existing /// </summary> private bool AddFormFile(LibCurl.MultiPartForm mf, string fileName, string field) { if (fileName != "") { if (!DrutNETBase.FileExists(fileName)) { sendLogEvent("Can't find file : " + fileName + "\n", "Curl", Enums.MessageType.Error); return(false); } else if ((new FileInfo(fileName).Length / 1024) > Enums.MAXFILESIZEKB) { sendLogEvent(fileName + " size is bigger than limit (" + (Enums.MAXFILESIZEKB / 1024).ToString() + "MB)" + "\n", "Curl", Enums.MessageType.Error); return(false); } else { LibCurl.CURLFORMcode res = mf.AddSection(LibCurl.CURLformoption.CURLFORM_COPYNAME, field, LibCurl.CURLformoption.CURLFORM_FILE, fileName, LibCurl.CURLformoption.CURLFORM_END); if (res != LibCurl.CURLFORMcode.CURL_FORMADD_OK) { sendLogEvent("Can't add Curl file: " + res.ToString() + "\n", "Curl", Enums.MessageType.Error); return(false); } else { return(true); } } } return(false); }
static public string[] ReadAutoCompleteFile(string path) { List <string> valList = new List <string>(); if (DrutNETBase.FileExists(path)) { TextReader autoCompleteFile = new StreamReader(path); string val; while ((val = autoCompleteFile.ReadLine()) != null) { valList.Add(val); } autoCompleteFile.Close(); } return(valList.ToArray()); }
public bool DownloadFile(string httpPath, string savePath) { try { if (_isloggedIn) { easy.SetOpt(LibCurl.CURLoption.CURLOPT_WRITEFUNCTION, wf); fileDownload = new FileStream(savePath, FileMode.Create); ///replace space with %20 string a = " "; string b = "&20"; httpPath = httpPath.Replace(a, b); easy.SetOpt(LibCurl.CURLoption.CURLOPT_URL, httpPath); LibCurl.CURLcode exec = easy.Perform(); //CURLcode exec = DrupCurlPerform(); double d = 0; easy.GetInfo(LibCurl.CURLINFO.CURLINFO_CONTENT_LENGTH_DOWNLOAD, ref d); //easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION,null); fileDownload.Close(); if ((d == 0) || (this.HttpConnectCode != 200) || (!DrutNETBase.FileExists(savePath))) { sendLogEvent("Can't download file with Curl: " + exec.ToString() + "\n", "Curl", Enums.MessageType.Error); return(false); } return(true); } else { sendLogEvent("CURL not logged-in", "Curl" + "\n", Enums.MessageType.Error); return(false); } } catch (Exception ex) { errorMessage(ex.Message); return(false); } }
public static string GetUniqueFileName(string sourceFN, bool useUnderScore) { //rename file if it exists int i = 0; string org = sourceFN; while (DrutNETBase.FileExists(sourceFN)) { string separator = "-"; if (useUnderScore) { separator = "_"; } sourceFN = System.IO.Path.GetDirectoryName(org) + "\\" + System.IO.Path.GetFileNameWithoutExtension(org) + separator + i.ToString() + System.IO.Path.GetExtension(org); i++; } return(sourceFN); }