0

I am trying to create a connection to a remote server to upload a file, the connection needs to be over SSL and I have only a bunch of ports available on routers from both sides. The connection seems to succeed, however the Stream requestStream = request.GetRequestStream(); times out. After inspecting tracing log, the following line seems suspicious:

System.Net Information: 0 : [7144] FtpControlStream#33675143 - Created connection from [myIP]:64230 to [theirIP]:990.

Although it says connection was created, I know that port 64230 is not open, and my guess is that's why it fails. So is it possible to specify which port to create a local connection from? Or maybe I'm missing something else?

[EDIT]:

I set up FTP site on IIS on my local machine for testing, to see what could possibly be going wrong, but I'm getting the same problem. What's interesting is that I can connect on pretty much any port with the same settings, except 990. I can now rule out the firewall, it doesn't seem to be the problem. Any other guesses? Here is the sample code:

string fileName = "file.pdf";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://[host]:990/file.pdf");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.EnableSsl = true;
request.UsePassive = true;
ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;
request.Credentials = new NetworkCredential("[host]|[username]", "[password]");
Stream requestStream = request.GetRequestStream();
FileStream stream = File.OpenRead(fileName);
const int bufferLength = 1024;
byte[] buffer = new byte[bufferLength];
int count = 0;
int readBytes = 0;
do
{
    readBytes = stream.Read(buffer, 0, bufferLength);
    requestStream.Write(buffer, 0, readBytes);
    count += readBytes;
}
while (readBytes != 0);

stream.Close();
requestStream.Close();

Console.WriteLine("Upload complete");
4

1 回答 1

-1

您的连接字符串不应该是:

ftps://[host]:990/file.pdf

另外我知道你说你可以排除防火墙,但它经常对 FTPS 感到头疼,也许这个 serverfault 答案可能有用:

使用 FTPS 时需要打开哪些防火墙端口?

于 2011-04-28T11:12:47.720 回答