4

以下のコード (.Net 2.0 である必要があります) を使用して、UAT サーバーで顧客の FTP サーバーに接続し、ファイルをアップロード/ダウンロードします。彼らが提供する自己署名証明書を使用して、ポート 990 経由で接続する必要があります。UAT サーバーからポート 990 の URI への接続を許可するように、ファイアウォール ルールを修正しました。

ただし (! :)) 回線でタイムアウトが発生します

 Stream requestStream = request.GetRequestStream();

タイムアウト時間を増やしても違いはありません。

私はウェブを見回しましたが、コードに欠けている明らかなものは何も見つかりませんでした。

CuteFTP を使用して UAT サーバーに接続すると、当然、正常に接続され、手動でファイル転送を行うことができます。WireShark を使用してネットワーク トラフィックを確認すると、FTP サーバーから応答が返されますが、ユーザー ID と pwd (コード用) のハンドシェイクは行われませんが、CuteFTP を介してすべてのネットワーク トラフィックは問題ありません。

証明書をチェックする場所で True を強制的に返します。


private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                string completeFTPPath = ConfigurationManager.AppSettings["FTPPath"];
                // get the object used to communicate with the server.
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(completeFTPPath);
                request.EnableSsl = true;
                request.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["FtpUserName"], ConfigurationManager.AppSettings["FtpPassword"]);
                request.Method = WebRequestMethods.Ftp.UploadFile;                

                ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications;

                // read file into byte array
                StreamReader sourceStream = new StreamReader(ConfigurationManager.AppSettings["LocalFilePath"]);
                byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                sourceStream.Close();
                request.ContentLength = fileContents.Length;

                // send bytes to server
                MessageBox.Show("GetRequestStream() start");
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();
                MessageBox.Show("GetRequestStream() end");

                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                MessageBox.Show("Response status: " + response.StatusDescription);
            }
            catch (WebException we)
            {
                MessageBox.Show(we.Message);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }

        }

  public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
        { return true; }

例: FTPPath - ftp://111.222.333.444:990/UAT/testFile.zip ; FtpUserName - ユーザー ID; FtpPassword = userPwd; LocalFilePath - c:\temp\testFile.zip

誰でもアイデアはありますか?一部の人々は上記のコードが機能しているようです。ティア。

4

5 に答える 5

1

ポート 990 にあるサーバーは、より標準的な明示的FTPS ではなく、暗黙的 FTPSをサポートしている可能性が最も高いです。暗黙の FTPS が FtpWebRequest でサポートされていない可能性があります (わかりません)。

その場合は、暗黙的および明示的な FTPS と SFTP の両方をサポートするedtFTPnet/PROをご覧ください。

于 2009-09-07T06:44:29.917 に答える
1

EnterpriseDT ライブラリを試してください。

于 2009-09-07T07:01:38.267 に答える
0

.Net でトレースをオンにして問題を再現し、結果のログを投稿してください。何が問題なのかを説明します。.Net 2.0 の FtpWebRequest にはいくつかの既知の問題があるため、そのうちの 1 つにも該当する可能性がありますが、表示しているコードだけで言うことはできません。トレースを有効にする手順については、http: //blogs.msdn.com/dgorti/archive/2005/09/18/471003.aspxを参照してください。

于 2009-08-31T01:54:03.583 に答える
-1

FTPを使用してファイルをアップロードする場合、通常、次のようにFtpWebRequestオブジェクトを作成します。

string address = "ftp://www.companyname.com/UAT/"
string fileName = "testFile.zip"
UriBuilder uriBuilder = new UriBuilder(address);
FtpWebRequest  request = (FtpWebRequest)WebRequest.Create(uriBuilder.ToString() + fileName);

これを試してみて、何が起こるか見てみましょう。これは明示的なSSLとポート990で機能することを私は知っています。

于 2009-10-13T16:33:36.290 に答える
-1

私もこれを最初に見ましたが、あまり光を当てませんでした。

たった今トレースを再度実行し、Durgaprasad の投稿で SSL system.diagnostics 設定を使用しました。

System.Net Verbose: 0 : [7016] WebRequest::Create(ftp://www.companyname.com:990/UAT/testFile.zip)
System.Net Information: 0 : [7016] FtpWebRequest#48285313::.ctor(ftp://www.companyname.com:990/UAT/testFile.zip)
System.Net Verbose: 0 : [7016] Exiting WebRequest::Create()     -> FtpWebRequest#48285313
System.Net Verbose: 0 : [7016] FtpWebRequest#48285313::GetRequestStream()
System.Net Information: 0 : [7016] FtpWebRequest#48285313::GetRequestStream(Method=STOR.)
System.Net.Sockets Verbose: 0 : [7016] Socket#31914638::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [7016] Exiting Socket#31914638::Socket() 
System.Net.Sockets Verbose: 0 : [7016] Socket#31914638::Connect(131:990#-2083582714)
System.Net.Sockets Verbose: 0 : [7016] Exiting Socket#31914638::Connect() 
System.Net Information: 0 : [7016] Associating FtpWebRequest#48285313 with FtpControlStream#18796293
System.Net.Sockets Verbose: 0 : [7016] Socket#31914638::Receive()
System.Net.Sockets Error: 0 : [7016] Exception in the Socket#31914638::Receive - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
System.Net.Sockets Verbose: 0 : [7016] Exiting Socket#31914638::Receive()   -> 0#0
System.Net.Sockets Verbose: 0 : [7016] Socket#31914638::Dispose()
System.Net Information: 0 : [7016] FtpWebRequest#48285313::(Releasing FTP connection#18796293.)
System.Net Error: 0 : [7016] Exception in the FtpWebRequest#48285313::GetRequestStream - The operation has timed out.
System.Net Error: 0 : [7016]    at System.Net.FtpWebRequest.GetRequestStream()
System.Net Verbose: 0 : [7016] Exiting FtpWebRequest#48285313::GetRequestStream() 

また、(前回これを実行したときに)ネットワーク チームに Netmon を実行してもらいました。


  TCP    kulccstgweb02:2673     companyname.com:microsoft -ds  ESTABLISHED
  TCP    kulccstgweb02:2678     companyname IP:ftps    ESTABLISHED
  TCP    kulccstgweb02:sms-chat  companyname IP:ftps    ESTABLISHED

ところで、FTPPath - " ftp://111.222.333.444:990/UAT/testFile.zip " は実際には " ftp://www.companyname.com:990/UAT/testFile.zip " であり、IP に解決されます. しかし、それがどのように違いを生むのかわかりません。

于 2009-08-31T04:37:44.070 に答える