首先服务器有提供FTP服务,自己要提供IP,用户名密码,及目录。然后用上传的类。 /// <summary>
        /// ftp方式上传 
        /// </summary>
        /// filePath 要上传的路径   filename 文件名
     /// ftpServerIP 服务器IP
       ///ftpUserID 用户名,  ftpPassword 密码
        public static int UploadFtp(string filePath, string filename, string ftpServerIP, string ftpUserID, string ftpPassword)
        {
            FileInfo fileInf = new FileInfo(filePath + "\\" + filename);
            string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
            FtpWebRequest reqFTP;
            // Create FtpWebRequest object from the Uri provided 
            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileInf.Name));
            try
            {
                // Provide the WebPermission Credintials 
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
 
                // By default KeepAlive is true, where the control connection is not closed 
                // after a command is executed. 
                reqFTP.KeepAlive = false;
 
                // Specify the command to be executed. 
                reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
 
                // Specify the data transfer type. 
                reqFTP.UseBinary = true;
 
                // Notify the server about the size of the uploaded file 
                reqFTP.ContentLength = fileInf.Length;
 
                // The buffer size is set to 2kb 
                int buffLength = 2048;
                byte[] buff = new byte[buffLength];
                int contentLen;
 
                // Opens a file stream (System.IO.FileStream) to read the file to be uploaded 
                //FileStream fs = fileInf.OpenRead(); 
                FileStream fs = fileInf.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
 
                // Stream to which the file to be upload is written 
                Stream strm = reqFTP.GetRequestStream();
 
                // Read from the file stream 2kb at a time 
                contentLen = fs.Read(buff, 0, buffLength);
 
                // Till Stream content ends 
                while (contentLen != 0)
                {
                    // Write Content from the file stream to the FTP Upload Stream 
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);
                }
 
                // Close the file stream and the Request Stream 
                strm.Close();
                fs.Close();
                return 0;
            }
            catch (Exception ex)
            {
                reqFTP.Abort();
                //  Logging.WriteError(ex.Message + ex.StackTrace);
                return -2;
            }
        }

解决方案 »

  1.   

    http://blog.sina.com.cn/s/blog_4178457501015oqd.html
      

  2.   

    如果FTP目录有data,可以以下方式
    ftp://" + ftpServerIP + "/data/"+ fileInf.Name
      

  3.   

    先在服务器上搭建一个ftp吧,用微软自带ftp就很方便。
      

  4.   

    为什么都推荐用FTP?首先说明我还真没用过.NET的FTP。
    但我推荐用remoting,方便,快捷,稳定。
      

  5.   

    http://www.cnblogs.com/magic-cube/archive/2012/08/03/2622159.html
      

  6.   

    .net上传文件到服务器除了ftp协议上传和http协议上传,还有其它方式上传文件嘛?
      

  7.   

    利用socket+tcp协议,自己写一个接收服务端,再写一个上传客户端。