亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#把文件上傳到服務(wù)器中的指定地址

 更新時間:2022年04月23日 11:40:22   作者:農(nóng)碼一生  
這篇文章介紹了C#實現(xiàn)文件上傳到服務(wù)器指定地址的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

一、建立連接

        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("未能連接!");
            }
        }

三、連接狀態(tài)

        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);
        }

到此這篇關(guān)于C#實現(xiàn)文件上傳到服務(wù)器指定地址的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 教你C#將CSV轉(zhuǎn)為Excel的實現(xiàn)方法

    教你C#將CSV轉(zhuǎn)為Excel的實現(xiàn)方法

    這篇文章主要介紹了C#?將CSV轉(zhuǎn)為Excel,轉(zhuǎn)換之后可執(zhí)行更多關(guān)于數(shù)據(jù)編輯、格式設(shè)置等操作,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2022-03-03
  • C# 獲取客戶端IPv4地址的示例代碼

    C# 獲取客戶端IPv4地址的示例代碼

    這篇文章主要介紹了C# 獲取客戶端IPv4地址的示例代碼,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-12-12
  • C#.NET中如何批量插入大量數(shù)據(jù)到數(shù)據(jù)庫中

    C#.NET中如何批量插入大量數(shù)據(jù)到數(shù)據(jù)庫中

    這篇文章主要給大家介紹C#.net中如何批量插入大量數(shù)據(jù)到數(shù)據(jù)庫中,本文涉及到C#.net中批量插入數(shù)據(jù)到數(shù)據(jù)庫中方面的內(nèi)容,對C#.net批量插入數(shù)據(jù)到數(shù)據(jù)庫中感興趣的朋友可以參考下本篇文章
    2015-10-10
  • C#設(shè)置右鍵菜單的方法

    C#設(shè)置右鍵菜單的方法

    這篇文章主要介紹了C#設(shè)置右鍵菜單的方法,實例分析了C#設(shè)置右鍵菜單的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • C#使用遠(yuǎn)程服務(wù)調(diào)用框架Apache Thrift

    C#使用遠(yuǎn)程服務(wù)調(diào)用框架Apache Thrift

    這篇文章介紹了C#使用遠(yuǎn)程服務(wù)調(diào)用框架Apache Thrift的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • Winform利用分頁控件實現(xiàn)導(dǎo)出PDF文檔功能

    Winform利用分頁控件實現(xiàn)導(dǎo)出PDF文檔功能

    當(dāng)前的Winform分頁控件中,當(dāng)前導(dǎo)出的數(shù)據(jù)一般使用Excel來處理,但是有框架的使用客戶希望分頁控件能夠直接導(dǎo)出PDF,所以本文整理了一下分頁控件導(dǎo)出PDF的處理過程,分享一下
    2023-03-03
  • C# 7.0 使用下劃線忽略使用的變量的原因分析

    C# 7.0 使用下劃線忽略使用的變量的原因分析

    這篇文章主要介紹了C# 7.0 使用下劃線忽略使用的變量的原因淺析,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-10-10
  • C#接口interface用法實例

    C#接口interface用法實例

    這篇文章主要介紹了C#接口interface用法,實例分析了C#接口的基本使用方法,需要的朋友可以參考下
    2015-06-06
  • C#實現(xiàn)讓窗體永遠(yuǎn)在窗體最前面顯示的實例

    C#實現(xiàn)讓窗體永遠(yuǎn)在窗體最前面顯示的實例

    這篇文章主要介紹了C#實現(xiàn)讓窗體永遠(yuǎn)在窗體最前面顯示,功能非常實用,需要的朋友可以參考下
    2014-07-07
  • c# 實現(xiàn)簡單的串口通訊

    c# 實現(xiàn)簡單的串口通訊

    這篇文章主要介紹了c# 如何實現(xiàn)簡單的串口通訊,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-03-03

最新評論