We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

Trying to open file from FTP and display in webmatrixRSS

5 replies

Last post Aug 05, 2011 04:19 AM by HCamper

  • Trying to open file from FTP and display in webmatrix

    Jun 29, 2011 11:59 AM|Shinji_88|LINK

    Hi guys,

    I am quite new to C# and ftp. 

    I was trying to connect to my intranet ftp to download a file but there is no avail. Any help would be apperciate.

     The code i was using in cshtml is:

    @functions{

    public static string DataSearchQuote(string symbol)

    {

    string xml;

    WebClient web =

    new WebClient();

    web.Credentials =

    new NetworkCredential("admin","");

    string serverURL =@"ftp://192.168.1.250/RC"+symbol+".LOG";

    byte[] Data = web.DownloadData(serverURL);

    xml = System.Text.Encoding.UTF8.GetString(Data);

    xml = xml.Replace( ",0", "");

    xml = xml.Replace(

    "@01", "");

    return xml;

    }

    }

    Exception Details: System.Net.WebException: The remote server returned an error: (502) Command not implemented.

    Source Error:

    Line 22:             quotes.Add(new Quote( @MyDataHelpers.DataSearchQuote(symbol)));
          

    [WebException: The remote server returned an error: (502) Command not implemented.]
       System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) +290
       System.Net.WebClient.DownloadData(Uri address) +106
       System.Net.WebClient.DownloadData(String address) +29
       ASP.MyDataHelpers.DataSearchQuote(String symbol) +168
       ASP._Page_default_cshtml.Execute() in default.cshtml:22
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +209
       System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +68
       System.Web.WebPages.WebPage.ExecutePageHierarchy() +152
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
       System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext context) +239

  • Re: Trying to open file from FTP and display in webmatrix

    Jun 30, 2011 05:13 AM|simtan|LINK

    Hello,

    I'm not quite sure, but it seems that the way you are referring to the file to download may not be quite right. Downloading files via FTP is slightly more complex than that; perhaps this article can help:

    http://msdn.microsoft.com/en-us/library/ms229711.aspx

    (When you're using WebMatrix with ASP.NET, you are using C#, so the entire .NET library is available to you and all of the documentation applies as well.)

    Hope this helps!

    Simon Tan
    Program Manager
    Web Platform and Tools
  • Re: Trying to open file from FTP and display in webmatrix

    Jul 01, 2011 11:02 PM|Shinji_88|LINK

    Thanks Simon for your advise, but I still could not connect to the ftp website.

    I change to the following code, it still prompt me the 502 error at FtpWebResponse response = (FtpWebResponse)request.GetResponse();

    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(

    "ftp://192.168.1.250/RC"+symbol+".LOG");

    request.Credentials =

    new NetworkCredential("admin", "");

    request.UseBinary =

    false;

    request.Timeout =

    10000;

    request.ReadWriteTimeout =

    10000;

    request.KeepAlive =

    false;

    request.Method = WebRequestMethods.Ftp.DownloadFile;

    FtpWebResponse response = (FtpWebResponse)request.GetResponse();

    Stream responseStream = response.GetResponseStream();

    Please advise. Thank you.

  • Re: Trying to open file from FTP and display in webmatrix

    Jul 04, 2011 06:51 AM|simtan|LINK

    Hello,

    Just curious - have you used a normal FTP client to try to download the file? (E.g. CuteFTP or some other tool?)

    Simon Tan
    Program Manager
    Web Platform and Tools
  • Re: Trying to open file from FTP and display in webmatrix

    Jul 20, 2011 01:45 AM|HCamper|LINK

    Hello @ Shinji_88,

    You may find this

     http://www.asp.net/general/videos/how-do-i-use-the-ftpwebrequest-class-to-create-an-ftp-connection-to-a-ftp-server   

    code sample and presentation at the ASP.NET Web site as part of the  "How to Collection" of use.

    The code is not Web Matrix specific but could be reused for your need.

    Martin

     

    Windows and Linux work Together IT-Pros
    Community Member Award 2011
  • Re: Trying to open file from FTP and display in webmatrix

    Aug 05, 2011 04:19 AM|HCamper|LINK

    Hello,

    Are you still having problems ?

    You might try using the new Feed Back site http://webmatrix.uservoice.com/forums/128313-suggestion-box .

    You might check the Microsoft Connect web site for what users have posted.

    Martin

     

    Windows and Linux work Together IT-Pros
    Community Member Award 2011