2009-08-31 10 views
4

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

(!:))私はそれは違いはありませんタイムアウト時間を増やした場合、私はライン

Stream requestStream = request.GetRequestStream();

のタイムアウトを取得します。

私はウェブ上を見てきましたが、コードにはっきりと見当たらないものは何も見つかりませんでした。

私はその後、UATサーバーに接続するためにCuteFTPのを使用している場合は、当然、それが正常に接続して、私は手動でファイル転送を行うことができます。 WireSharkを使ってネットワークトラフィックを調べると、FTPサーバーからの応答が得られますが、useridと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 - userID; FtpPassword = userPwd; LocalFilePath - C:\ TEMP \ testFile.zip

誰でも任意のアイデア?上記のコードを動作させる人もいるようです。 TIA。

答えて

0

.Netでトレースをオンにして問題を再現し、結果のログをポストすると、何がうまくいかないか教えてくれます。 .Net 2.0のFtpWebRequestにはいくつかの既知の問題があるので、それらのうちの1つを押すこともできますが、表示しているコードだけでは言い表せません。トレースをオンにする方法について説明ここで見つけることができます:http://blogs.msdn.com/dgorti/archive/2005/09/18/471003.aspx

0

私はもともとまた、これを見て持っていたが、それは私に多くの光を当てるしませんでした。

私はちょうど今、もう一度トレースを実行し、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()

、(これを実行する前の時点で)私は、ネットワークモニターを実行するために、ネットワークチームを持って、彼らは以下から暗示、コードに関連したことを:ところで


    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"はactaully "ftp://www.companyname.com:990/UAT/testFile.zip"であり、IPに解決されます。しかし、私はそれがどのように違いを生むのか分かりません。ポート990上にある

+0

で動作します知っていますホスト名「111.222.333.444」は「www.company.com」という名前ではなく、証明書名の照合に失敗します。これはあなたの問題だろうか? –

1

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

その場合、両方の暗黙的および明示的FTPSをサポートしていedtFTPnet/PROを見て、取るだけでなく、SFTP。

+0

これを確認できますか?これは私の問題かもしれないと思います。 – PeterX

+0

レビューもできます:http://ftps.codeplex.com/ – PeterX

0

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

関連する問題