FileInfo fiLocalFile = new FileInfo(sSrcFileName); ftpWebReq = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + sServerIP + "/" + sDstFileName)); ftpWebReq.Credentials = new NetworkCredential(sUserID, sPassword); ftpWebReq.UsePassive = false; ftpWebReq.KeepAlive = false; ftpWebReq.Method = WebRequestMethods.Ftp.UploadFile; ftpWebReq.UseBinary = true; ftpWebReq.ContentLength = fiLocalFile.Length; MessageBox.Show(ftpWebReq.ToString()); int iBuffLen = 2048; byte[] baBuff = new byte[iBuffLen]; int iConLen; FileStream fsLocalFile = fiLocalFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); Stream stmReq = ftpWebReq.GetRequestStream(); iConLen = fsLocalFile.Read(baBuff, 0, iBuffLen); while (iConLen != 0) { stmReq.Write(baBuff, 0, iConLen); iConLen = fsLocalFile.Read(baBuff, 0, iBuffLen); } stmReq.Close(); fsLocalFile.Close();
以上是代码。
这句话报错:Stream stmReq = ftpWebReq.GetRequestStream();
报错提示:系统错误。
我是内网,上传至外网ftp,会是什么问题导致?
ftpWebReq.UsePassive = true;
有没有报错的详细信息
FileInfo fiLocalFile = new FileInfo(sSrcFileName);
ftpWebReq.ContentLength = fiLocalFile.Length;
不能一下全部读取加载到内存中,应该是有个指定特定的大小,采用数组偏移形式依次加载到内存中。
建议你改用winscp吧