日期:2014-05-17  浏览次数:21278 次

C#把文件上传到服务器出问题
 /// <summary>
        /// 上传
        /// </summary>
        /// <param name="localFile">要上传到FTP服务器的文件</param>
        /// <param name="ftpPath">FTP地址</param>
        /// <param name="ftpUser">用户名</param>
        /// <param name="ftpPassword">密码</param>
        public static void UpLoadFile(string localFile, string ftpPath, string ftpUser, string ftpPassword)
        {
            if (ftpUser == null)
            {
                ftpUser = "";
            }
            if (ftpPassword == null)
            {
                ftpPassword = "";
            }
            if (!File.Exists(localFile))
            {
                MessageBox.Show("(上传文件)文件:“" + localFile + "” 不存在!");
                return;
            }
            FtpWebRequest ftpWebRequest = null;
            FileStream localFileStream = null;
            Stream requestStream = null;
            try
            {
                //ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpPath));
                FtpWebRequest uploadRequest = (FtpWebRequest)WebRequest.Create(ftpPath);
                ftpWebRequest.Credentials = new NetworkCredential(ftpUser, ftpPassword);
                ftpWebRequest.UseBinary = true;
                ftpWebRequest.KeepAlive = false;
                ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile;
                ftpWebRequest.ContentLen