C#怎么把文件上传到服务器中的指定地址
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这篇文章主要介绍了C#怎么把文件上传到服务器中的指定地址的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇C#怎么把文件上传到服务器中的指定地址文章都会有所收获,下面我们一起
千家信息网最后更新 2026年11月01日C#怎么把文件上传到服务器中的指定地址
这篇文章主要介绍了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#怎么把文件上传到服务器中的指定地址"知识都有一定的了解,大家如果还想学习更多知识,欢迎关注行业资讯频道。
文件
地址
服务器
C#
服务
知识
内容
篇文章
价值
操作简单
文章
易懂
更多
状态
看吧
行业
资讯
资讯频道
频道
学习
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技股
山东特亿宝互联网科技有限公司
互联网金融监管科技数据
互联网与科技金融数据
互联网巨头投资的硬核科技
深圳互联网科技怎么样
博兴的互联网电子科技公司
花神(南京)互联网科技有限公司
搜狐科技互联网
迪庆互联网科技招生
科技大学互联网
卓翼科技产业互联网合作
互联网金融科技名词解释
徐州市互联网科技有限公司
美国互联网科技实力
互联网科技数字货币
互联网科技包装股份有限公司上市
昆明中奇联合互联网科技
银川新华互联网科技学校原画
悟空问答互联网科技
咖啡豆
撒么互联网科技公司
互联网前沿科技
茂名市互联网科技产业园
现代互联网科技股
开一家科技互联网公司需要多少钱
晋城互联网科技
工业互联网等科技实现智能化赋能
锡山区互联网智能科技产品供应
互联网科技创业有什么好项目