您好,登錄后才能下訂單哦!
這篇文章主要介紹了C#怎么把文件上傳到服務器中的指定地址的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇C#怎么把文件上傳到服務器中的指定地址文章都會有所收獲,下面我們一起來看看吧。
public string connectFTP(string vPath, string vUID, string vPassword) { string errormsg = ""; Process proc = new Process(); try { proc.StartInfo.FileName = "cmd.exe"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.CreateNoWindow = true; proc.Start(); string dosLine = "net use " + vPath + " " + vPassword + " /user:" + vUID; proc.StandardInput.WriteLine(dosLine); proc.StandardInput.WriteLine("exit"); while (!proc.HasExited) { proc.WaitForExit(1000); } errormsg = proc.StandardError.ReadToEnd(); proc.StandardError.Close(); } catch (Exception ex) { //throw ex; //MessageBox.Show(ex.Message); } finally { proc.Close(); proc.Dispose(); } return errormsg; }
public void UploadFile(string vPath, string vUID, string vPassword, string vLocalPath, string file) { bool status = false; status = connectState(vPath, vUID, vPassword); if (status) { DirectoryInfo theFolder = new DirectoryInfo(vPath + "/" + file); string filename = vLocalPath; Transport(vLocalPath, vPath + "/" + file); //System.Diagnostics.Process.Start(vPath); } else { mesLog.Info("未能連接!"); //MessageBox.Show("未能連接!"); } }
public static bool connectState(string vPath, string vUID, string vPassword) { bool Flag = false; Process proc = new Process(); try { proc.StartInfo.FileName = "cmd.exe"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.CreateNoWindow = true; proc.Start(); string dosLine = "net use " + vPath + " " + vPassword + " /user:" + vUID; proc.StandardInput.WriteLine(dosLine); proc.StandardInput.WriteLine("exit"); while (!proc.HasExited) { proc.WaitForExit(1000); } string errormsg = proc.StandardError.ReadToEnd(); proc.StandardError.Close(); if (string.IsNullOrEmpty(errormsg)) { Flag = true; } else { throw new Exception(errormsg); } } catch (Exception ex) { //throw ex; //MessageBox.Show(ex.Message); } finally { proc.Close(); proc.Dispose(); } return Flag; }
public static void Transport(string src, string fileName) { FileStream inFileStream = new FileStream(src, FileMode.Open); FileStream outFileStream = new FileStream(fileName, FileMode.OpenOrCreate); byte[] buf = new byte[inFileStream.Length]; int byteCount; while ((byteCount = inFileStream.Read(buf, 0, buf.Length)) > 0) { outFileStream.Write(buf, 0, byteCount); } inFileStream.Flush(); inFileStream.Close(); outFileStream.Flush(); outFileStream.Close(); File.Delete(src); }
關于“C#怎么把文件上傳到服務器中的指定地址”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“C#怎么把文件上傳到服務器中的指定地址”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。