2015-01-02 3 views
1

디버그에서 VS2013을 실행하는 동안 서버에 FTP로 업로드하고 파일을 업로드 할 수 있지만 릴리스 | x86 System.Net.FtpWebRequest.GetRequestStream()을 호출하는 줄에서 "원격 서버에 연결할 수 없습니다"라는 오류 메시지가 나타납니다. WinSCP를 사용하여 FTP에 접속하고 파일을 업로드 할 수 있습니다. WireShark를 실행하고 내 코드의 릴리스 버전에서 전혀 패킷을 보지 못했지만 VS2013 내의 디버그 모드에서 실행될 때 모든 관련 패킷을 보았습니다. 나는 방화벽이 없으며 정말로 나를 곤란하게 만든다. 어떤 도움이라도 대단히 감사하겠습니다. - 척System.Net.FtpWebRequest.GetRequestStream()에서 원격 서버에 연결할 수 없습니다.

public bool UploadToFtp(string sFtpServer, string sFtpUserName, string sFtpPassword, string sSourceLocationPath, string sFtpDestinationPath, StringBuilder sbLogMessage) 
    { 
     bool bUpload; 
     try 
     { 
      var oFile = new FileInfo(sSourceLocationPath); 
      var oUri = new Uri(sFtpServer + sFtpDestinationPath + oFile.Name); 
      var oFtp = (FtpWebRequest)WebRequest.Create(oUri); 
      oFtp.Credentials = new NetworkCredential(sFtpUserName, sFtpPassword); 
      oFtp.KeepAlive = false; 
      oFtp.UseBinary = true; 
      oFtp.UsePassive = true; 
      oFtp.Timeout = 10000000; 
      oFtp.ReadWriteTimeout = 10000000; 
      oFtp.Method = WebRequestMethods.Ftp.UploadFile; 
      oFtp.ContentLength = oFile.Length; 
      var arrContent = File.ReadAllBytes(oFile.FullName); 
      using (var oFileStream = oFile.OpenRead()) 
      { 
       using (var oStream = oFtp.GetRequestStream()) 
       { 
        int iReadBytes; 
        do 
        { 
         iReadBytes = oFileStream.Read(arrContent, 0, int.Parse(oFile.Length.ToString(CultureInfo.InvariantCulture))); 
         oStream.Write(arrContent, 0, iReadBytes); 
        } while (iReadBytes != 0); 

        bUpload = true; 
        oStream.Flush(); 
        oStream.Close(); 
        oFileStream.Close(); 
       } 
      } 
      File.Delete(sSourceLocationPath + oFile.Name); 
     } 
     catch (Exception ex) 
     { 
      LogMessage(ex.Message); 
      bUpload = false; 
     } 
     return bUpload; 
    } 

***** 편집 ***** 나는 제안 네트워크 추적 로그를 생성하고 (참고 :이 목록에 실제 IP 번호와 파일 이름을 변경 한) 다음과 같은 결과를 얻었다 :

System.Net Verbose: 0 : [27252] WebRequest::Create(ftp://1.2.3.4//file.zip) 
System.Net Information: 0 : [27252] FtpWebRequest#28316044::.ctor(ftp://1.2.3.4//file.zip) 
System.Net Verbose: 0 : [27252] Exiting WebRequest::Create() -> FtpWebRequest#28316044 
System.Net Verbose: 0 : [27252] FtpWebRequest#28316044::GetRequestStream() 
System.Net Information: 0 : [27252] FtpWebRequest#28316044::GetRequestStream(Method=STOR.) 
System.Net Information: 0 : [27252] Current OS installation type is 'Client'. 
System.Net Verbose: 0 : [27252] ServicePoint#39974954::ServicePoint(1.2.3.4:21) 
System.Net.Sockets Verbose: 0 : [27252] Socket#24230272::Socket(AddressFamily#2) 
System.Net.Sockets Verbose: 0 : [27252] Exiting Socket#24230272::Socket() 
System.Net.Sockets Verbose: 0 : [27252] Socket#16745860::Socket(AddressFamily#23) 
System.Net.Sockets Verbose: 0 : [27252] Exiting Socket#16745860::Socket() 
System.Net.Sockets Verbose: 0 : [27252] DNS::TryInternalResolve(1.2.3.4) 
System.Net.Sockets Verbose: 0 : [27252] Socket#24230272::Connect(1.2.3.4:21#1294145406) 
System.Net.Sockets Error: 0 : [27252] Socket#24230272::UpdateStatusAfterSocketError() - TimedOut 
System.Net.Sockets Error: 0 : [27252] Exception in Socket#24230272::Connect - 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 1.2.3.4:21. 
System.Net Error: 0 : [27252] Exception in FtpWebRequest#28316044::GetRequestStream - Unable to connect to the remote server. 
    at System.Net.FtpWebRequest.GetRequestStream() 
System.Net Verbose: 0 : [27252] Exiting FtpWebRequest#28316044::GetRequestStream() 
+0

전원을 켜고 네트워크, 지침 [여기] (http://msdn.microsoft.com/en-us/library/hyb3xww8 (V = 대. 110) .aspx) – user957902

+0

Visual Studio 외부에서 Release | x86 버전을 어떻게 실행하고 있습니까? – user957902

+0

@ user957902 bin \ x86 \ Release 디렉토리에서 .exe 파일을 두 번 클릭하여 Release | x86을 실행 중입니다 ... 네트워크 추적을 지금 활성화하면 찾은 것을 알려줍니다. –

답변

0

좋은 제안은 네트워크 추적 기능을 사용하는 것이 었습니다 그러나, 그것은 범인이었던 시스템 관리자에 의해 관리 명 Bitdefender '엔드 포인트 보안'이었다 (감사 user957902를!). 나는 어떤 종류의 방화벽이 스텔스 모드로 실행되어 일부 응용 프로그램 (컴파일 된 내용)에서 FTP 트래픽을 차단하고 다른 사용자 (VS2013)의 통과를 허용한다고 생각합니다. 이런 종류의 문제를 해결할 때 항상 보안 소프트웨어를 살펴보고 sys 관리자에게 질문하십시오. 특히 트래픽이 일부 경우에는 작동하지만 다른 경우에는 그렇지 않은 경우에는 -이 유형의 유틸리티를 안팎으로 통치 해보십시오 .

관련하여 실제로 수행되는 상황을 확인하기 위해 추적을 척