最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2022年04月23日 11:40:22   作者:農(nóng)碼一生  
這篇文章介紹了C#實現(xiàn)文件上傳到服務(wù)器指定地址的方法,文中通過示例代碼介紹的非常詳細。對大家的學(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#?AsyncLocal如何實現(xiàn)Thread間傳值

    淺析C#?AsyncLocal如何實現(xiàn)Thread間傳值

    這篇文章主要是來和大家一起討論一下C#?AsyncLocal如何實現(xiàn)Thread間傳值,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01
  • c# dynamic的使用詳解

    c# dynamic的使用詳解

    這篇文章主要介紹了c# dynamic的使用詳解,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-04-04
  • C#實現(xiàn)一階卡爾曼濾波算法的示例代碼

    C#實現(xiàn)一階卡爾曼濾波算法的示例代碼

    這篇文章主要介紹了C#實現(xiàn)一階卡爾曼濾波算法的示例代碼,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-04-04
  • C#實現(xiàn)獲取枚舉中元素個數(shù)的方法

    C#實現(xiàn)獲取枚舉中元素個數(shù)的方法

    這篇文章主要介紹了C#實現(xiàn)獲取枚舉中元素個數(shù)的方法,是深入理解C#程序設(shè)計所需要掌握的基本技巧,需要的朋友可以參考下
    2014-08-08
  • C#小程序15位轉(zhuǎn)18位身份證號代碼

    C#小程序15位轉(zhuǎn)18位身份證號代碼

    現(xiàn)在我們使用的都是18位身份證號,而以前都是15位身份證號,而如何將15位身份證號轉(zhuǎn)18位身份證號轉(zhuǎn)換為18位身份證號呢?
    2013-02-02
  • C#連接數(shù)據(jù)庫的幾種方法

    C#連接數(shù)據(jù)庫的幾種方法

    這篇文章介紹了C#連接數(shù)據(jù)庫的幾種方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • C#定位txt指定行的方法小例子

    C#定位txt指定行的方法小例子

    近日,在開發(fā)CAD插件時需要定位TXT文件指定行并將其選中,在網(wǎng)絡(luò)找了一下沒有找到現(xiàn)成的,自己編了一個定位程序,實現(xiàn)了定位功能..與大家分享
    2013-04-04
  • C#身份證驗證小例子

    C#身份證驗證小例子

    C#身份證驗證小例子,需要的朋友可以參考一下
    2013-04-04
  • C# 注冊表 操作實現(xiàn)代碼

    C# 注冊表 操作實現(xiàn)代碼

    Windows 操作系統(tǒng)的注冊表包含了很多有關(guān)計算機運行的配置方式,打開注冊表我們可以看到注冊表是按類似于目錄的樹結(jié)構(gòu)組織的
    2009-07-07
  • C# 中使用 Exceptionless的方法

    C# 中使用 Exceptionless的方法

    這篇文章主要介紹了C# 中使用 Exceptionless的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-12-12

最新評論

安宁市| 陆良县| 武清区| 岱山县| 旬邑县| 商洛市| 奈曼旗| 定襄县| 夏津县| 凉山| 大同市| 浦城县| 荥阳市| 安宁市| 盐源县| 陆良县| 攀枝花市| 萨迦县| 石棉县| 龙里县| 宕昌县| 年辖:市辖区| 上思县| 格尔木市| 苏尼特左旗| 大足县| 常山县| 定州市| 沙湾县| 庆元县| 伊通| 五大连池市| 息烽县| 广南县| 凤阳县| 娱乐| 那曲县| 扎赉特旗| 宁国市| 新乐市| 福安市|