作者:哥这么好的人你去哪找 | 来源:互联网 | 2023-10-12 16:55
本篇内容主要讲解“C#服务器NFS共享文件夹搭建与上传图片文件怎么实现”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“C#服务器NFS共享文件夹搭建与上传图片文件怎么实现”吧!
nfs共享文件夹实现步骤
基于:Windows server2016,其他版本大同小异
安装NFS组件(如果已安装略过)






在源服务器建立nfs文件夹共享










到此服务器创建NFS就完成了,接下来我们开始程序上传
使用net dos命令
尝试连接共享文件夹
bool status = connectState(@"\\IP\uploadImages", "用户登录名", "登录密码");
///
/// 连接共享文件
///
/// 共享文件地址
/// 用户名
/// 密码
/// true:连接成功 false:连接失败
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;
}
///
/// 选择图片或文件上传至服务器nfs共享文件夹
///
public void DosCopyImage()
{
if (status == false)
{
GLOBALS.msgbox("连续服务器失败!");
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);//复制文件夹下的所有文件、目录到指定的文件夹
GLOBALS.msgbox("上传成功!");
}
catch (Exception)
{
}
}
使用这个方法之前,先打开cmd窗口,用dos命令运行是否正常
net use错误解决方案:
错误号5,拒绝访问:很可能你使用的用户不是管理员权限的,先提升权限;
错误号51,Windows无法找到网络路径:网络有问题;
错误号53,找不到网络路径:ip地址错误;目标未开机;目标lanmanserver服务未启动;目标有防火墙(端口过滤);
错误号67,找不到网络名:你的lanmanworkstation服务未启动或者目标删除了uploadImages$;
错误号1219,提供的凭据与已存在的凭据集冲突:你已经和对方建立了一个uploadImages$,请删除再连;
错误号1326,未知的用户名或错误密码:原因很明显了;
到此,相信大家对“C#服务器NFS共享文件夹搭建与上传图片文件怎么实现”有了更深的了解,不妨来实际操作一番吧!这里是编程笔记网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!