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

C#服務(wù)器NFS共享文件夾搭建與上傳圖片文件的實(shí)現(xiàn)

 更新時間:2022年07月22日 11:32:24   作者:櫻花花  
本文主要介紹了C#服務(wù)器NFS共享文件夾搭建與上傳圖片文件的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

C#Windows server2016服務(wù)器搭建NFS共享文件夾與C#上傳圖片到共享文件夾

nfs共享文件夾實(shí)現(xiàn)步驟

基于:Windows server2016,其他版本大同小異

安裝NFS組件(如果已安裝略過)

 

在源服務(wù)器建立nfs文件夾共享

到此服務(wù)器創(chuàng)建NFS就完成了,接下來我們開始程序上傳

使用net dos命令

嘗試連接共享文件夾

bool status = connectState(@"\\IP\uploadImages", "用戶登錄名", "登錄密碼");
        /// <summary>
        /// 連接共享文件
        /// </summary>
        /// <param name="path">共享文件地址</param>
        /// <param name="userName">用戶名</param>
        /// <param name="passWord">密碼</param>
        /// <returns>true:連接成功 false:連接失敗</returns>
        public static bool connectState(string path, string userName, string passWord)
        {
            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 " + path + " " + passWord + " /user:" + userName;
                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;
            }
            finally
            {
                proc.Close();
                proc.Dispose();
            }
            return Flag;
        }
        /// <summary>
        /// 選擇圖片或文件上傳至服務(wù)器nfs共享文件夾
        /// </summary>
        public void DosCopyImage()
        {
            if (status == false)
            {
                GLOBALS.msgbox("連續(xù)服務(wù)器失敗!");
                return;
            }
            string id = DateTime.Now.ToString("yyyyMMddHHmmss");
            string isPath = DateTime.Now.ToString("yyyy-MM-dd");
            string Path = IISPATH + isPath;
            if (!Directory.Exists(IISPATH))
            {
                Directory.CreateDirectory(IISPATH);
            }
            string txtFilePath = "";
            OpenFileDialog openFileDialogTemp = new OpenFileDialog();
            openFileDialogTemp.Title = "選擇要上傳的圖片";
            openFileDialogTemp.Filter = "*.jpg,*.png,|*.jpg;*.png;";//如需上傳文件把文件添加上即可
            DialogResult dr = openFileDialogTemp.ShowDialog();
            if (!File.Exists(openFileDialogTemp.FileName))
            {
                GLOBALS.msgbox("照片為空,請選擇圖片");
                return;
            }
            if (dr == DialogResult.OK)
            {
                txtFilePath = openFileDialogTemp.FileName;
 
            }
            if (txtFilePath.Trim() == "")
            {
                GLOBALS.msgbox("請選擇文件!");
                return;
            }
            string filePath = this.txtFilePath.Text;
            string uploadUrl = IISPATH + isPath + "/" + id + ".jpg";
            try
            {
                File.Copy(filePath, uploadUrl);//復(fù)制文件夾下的所有文件、目錄到指定的文件夾
 
                GLOBALS.msgbox("上傳成功!");
            }
            catch (Exception)
            {
 
            }
        }

使用這個方法之前,先打開cmd窗口,用dos命令運(yùn)行是否正常

  • 命令:打開連接:net use \\IP地址\uploadImages$ 密碼/user:用戶名  注意:只有三個空格
  • 刪除連接:net use \\IP地址\uploadImages$ 密碼/user:用戶名\del

net use錯誤解決方案:

  • 錯誤號5,拒絕訪問:很可能你使用的用戶不是管理員權(quán)限的,先提升權(quán)限;
  • 錯誤號51,Windows無法找到網(wǎng)絡(luò)路徑:網(wǎng)絡(luò)有問題;
  • 錯誤號53,找不到網(wǎng)絡(luò)路徑:ip地址錯誤;目標(biāo)未開機(jī);目標(biāo)lanmanserver服務(wù)未啟動;目標(biāo)有防火墻(端口過濾);
  • 錯誤號67,找不到網(wǎng)絡(luò)名:你的lanmanworkstation服務(wù)未啟動或者目標(biāo)刪除了uploadImages$;
  • 錯誤號1219,提供的憑據(jù)與已存在的憑據(jù)集沖突:你已經(jīng)和對方建立了一個uploadImages$,請刪除再連;
  • 錯誤號1326,未知的用戶名或錯誤密碼:原因很明顯了;

到此這篇關(guān)于C#服務(wù)器NFS共享文件夾搭建與上傳圖片文件的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)C#服務(wù)器搭建與上傳圖片文件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

彝良县| 友谊县| 临武县| 南丰县| 克山县| 滨州市| 眉山市| 东阳市| 伊吾县| 买车| 开江县| 邹城市| 河西区| 思南县| 宜宾市| 密山市| 通江县| 苍山县| 福建省| 宜宾市| 油尖旺区| 峨山| 阳信县| 德令哈市| 即墨市| 德惠市| 梓潼县| 太保市| 涪陵区| 海宁市| 宝鸡市| 桃源县| 阿鲁科尔沁旗| 金乡县| 织金县| 安西县| 宁远县| 西安市| 米脂县| 将乐县| 郯城县|