我在从 C# 上传文件到 FTP 服务器时遇到了一些问题。我的代码在本地主机上运行良好,但在实时环境中它一直给我一个The operation has timed out.
例外。
我使用以下代码:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpPath + "/orders.csv");
request.UsePassive = true;
request.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Timeout = -1;
StreamReader sourceStream = new StreamReader(context.Server.MapPath("~/App_Data/orders.csv"));
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
ftpPath
我的 FTP 服务器的 URL在哪里:ftp: //myserver.com
有谁知道我在这里做错了什么?:-)
提前致谢。