如何在后台把本地文件传到服务器的指定目录中 比如我在本地“C:\aa.doc”文件,通过代码传到服务器的目录D:\Ftp下请问下如何写代码,在网上找了N久没找到 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 WebClient myWebClient = new WebClient(); myWebClient.Credentials = CredentialCache.DefaultCredentials; FileStream fs = new FileStream(df.GetValue("filePath"), FileMode.Open, FileAccess.Read);//要上传的文件 BinaryReader r = new BinaryReader(fs); byte[] postArray = r.ReadBytes((int)fs.Length); Stream postStream = myWebClient.OpenWrite("D:\\FtpRoot", "PUT"); postStream.Write(postArray, 0, postArray.Length); postStream.Close(); fs.Dispose();这个是我写的代码,但代码到D:\FtpRoot那提示没权限,但我FtpRoot已经给everyone开了完全控制了 客户端new System.Net.WebClient().UploadFile("服务器地址/一般处理程序.ashx", "FilePath"); 服务器端用一般处理程序最简单using System;using System.Collections.Generic;using System.Web;namespace WebApplication1{ /// <summary> /// Handler2 的摘要说明 /// </summary> public class Handler2 : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Request.Files[0].SaveAs("D:\\Ftp\\aa.doc"); context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); } public bool IsReusable { get { return false; } } }} 我已知了路径和文件 怎么通过ashx传呢,还是没太懂 上传的时候,还是用WebClient,ashx是在服务器端的 new System.Net.WebClient().UploadFile("服务器地址/一般处理程序.ashx", "FilePath"); FilePath如何在ashx里得到呢? Stream postStream = myWebClient.OpenWrite("D:\\Be20\\FtpRoot", "PUT"); Stream postStream = myWebClient.OpenWrite("D:\\Be20\\FtpRoot", "PUT");在这一步提交时,提示目录没有权限,这是为什么呢? 多个<input type="file">上传文件 C#中枚举和访问权限 UDP广播本机屏幕 数据丢失导致花屏。 access 如何实现按姓名查找记录,怎么会提示少一个参数 问个简单的白痴性问题! c# winform 如何动态删除和删除控件 急,在线等,在本地网页中调用服务器上的数据库时出现下面错误提示, 求多线程运用的例子,中等难度,有说明,学习用!!!欢迎来顶~~~~ (求助)基于数据采集仪的 C#振动数据采集程序 多次点击报错为空求原因 关于MVC的问题求助 this.Dispose();错误
myWebClient.Credentials = CredentialCache.DefaultCredentials;
FileStream fs = new FileStream(df.GetValue("filePath"), FileMode.Open, FileAccess.Read);//要上传的文件
BinaryReader r = new BinaryReader(fs);
byte[] postArray = r.ReadBytes((int)fs.Length);
Stream postStream = myWebClient.OpenWrite("D:\\FtpRoot", "PUT");
postStream.Write(postArray, 0, postArray.Length);
postStream.Close();
fs.Dispose();这个是我写的代码,但代码到D:\FtpRoot那提示没权限,但我FtpRoot已经给everyone开了完全控制了
new System.Net.WebClient().UploadFile("服务器地址/一般处理程序.ashx", "FilePath"); 服务器端用一般处理程序最简单
using System;
using System.Collections.Generic;
using System.Web;namespace WebApplication1
{
/// <summary>
/// Handler2 的摘要说明
/// </summary>
public class Handler2 : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Request.Files[0].SaveAs("D:\\Ftp\\aa.doc");
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
} public bool IsReusable
{
get
{
return false;
}
}
}
}
FilePath如何在ashx里得到呢?
在这一步提交时,提示目录没有权限,这是为什么呢?