2011-06-30 29 views
0

我在ASP.NET webservice中有一個簡單的類。它運行在我的本地系統,甚至在我已經設置了開發環境很好,但每當我嘗試發送生產服務器我得到下面的錯誤上的一個文件:在IIS7.5和.NET 4.0上使用FTPWebRequest時出錯

Exception Error: The underlying provider failed on Open. 

這裏是代碼被稱爲:

public class FTPHelper 
{ 
     public static string SendFile(string ftpuri, string username, string password, string ftppath, string filename, byte[] datatosend) 
     { 
      if (ftppath.Substring(ftppath.Length - 1) != "/") 
      { 
       ftppath += "/"; 
      } 
      FtpWebRequest ftp = (FtpWebRequest) FtpWebRequest.Create(ftpuri + ftppath + filename); 
      ftp.Method = WebRequestMethods.Ftp.UploadFile; 
      ftp.Credentials = new NetworkCredential(username, password); 
      ftp.UsePassive = true; 
      ftp.ContentLength = datatosend.Length; 
      Stream requestStream = ftp.GetRequestStream(); 
      requestStream.Write(datatosend, 0, datatosend.Length); 
      requestStream.Close(); 

      FtpWebResponse ftpresponse = (FtpWebResponse)ftp.GetResponse(); 

      return ftpresponse.StatusDescription; 
     } 
    } 

如何解決此問題。服務器是在Windows 2008 Server上運行的IIS 7.5。我正在使用.NET 4.0。是否有一個簡單的原因,爲什麼FtpWebResponse不會工作?

如果這是一個安全問題,那麼有沒有辦法解決它?我需要馬上得到這個工作。

回答

0

這是一個安全問題,網站運行的用戶沒有權限建立FTP連接。我是一名程序員,而不是一個網站管理員,所以我不知道如何做到這一點。在IIS上搜索微軟的IIS幫助後,終於通過了我的方式。改變用戶的解決方案是在超級用戶:

https://superuser.com/q/307168/68967

如果任何人有任何更好的解決方案,請回復。如果有人認爲這會打開安全問題,請發佈更多信息。

+0

我大吃一驚,一個星期後,沒有一個人可以幫助我與此。即使有獎金,也沒有人有答案。 – stephenbayer