在以下情况下会发生此错误:
public void UploadFile()
{
try
{
var fileName = "myFile";
var ftpFilePath = "ftp://xxx.xxx.xxx/myfolder/";
WebRequest.DefaultWebProxy = new WebProxy();
var ftpRequest = WebRequest.Create(requestUri) as FtpWebRequest;
ftpRequest.Credentials = new NetworkCredential("user", "password");
ftpRequest.Method = method;
ftpRequest.KeepAlive = false;
ftpRequest.UseBinary = false;
ftpRequest.UsePassive = false;
ftpRequest.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnValidateCertificate);
var requestStream = ftpRequest.GetRequestStream();
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[1024];
while (true)
{
int readSize = fileStream.Read(buffer, 0, buffer.Length);
if (readSize == 0)
{
break;
}
requestStream.Write(buffer, 0, readSize);
}
fileStream.Close();
requestStream.Close();
}
catch (Exception exception)
{
//...
}
}
当我在localhost和本地网络上使用FTP时,它运行良好。 但是当我尝试使用公共IP地址连接到服务器时。 发生此错误。当我使用filezilla连接到具有公共IP地址的服务器时,它没问题。请帮帮我!!