比如我在本地“C:\aa.doc”文件,通过代码传到服务器的目录D:\Ftp下
请问下如何写代码,在网上找了N久没找到

解决方案 »

  1.   

    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开了完全控制了
      

  2.   

    客户端
    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;
                }
            }
        }
    }
      

  3.   

    我已知了路径和文件 怎么通过ashx传呢,还是没太懂
      

  4.   

    上传的时候,还是用WebClient,ashx是在服务器端的
      

  5.   

    new System.Net.WebClient().UploadFile("服务器地址/一般处理程序.ashx", "FilePath");  
    FilePath如何在ashx里得到呢?
      

  6.   

    Stream postStream = myWebClient.OpenWrite("D:\\Be20\\FtpRoot", "PUT");
      

  7.   

    Stream postStream = myWebClient.OpenWrite("D:\\Be20\\FtpRoot", "PUT");
    在这一步提交时,提示目录没有权限,这是为什么呢?