locked
Trying to connect to a network scanner and view image files RRS feed

  • Question

  • User1352128867 posted

    I'm working on some legacy code that has no comments at all, but here are the circumstances. I need to connect to a network scanner and access a particular folder. The username and password are set up. Here is what was given to me:

                    FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(navigate);
                    ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                    ftp.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["hpUser"], ConfigurationManager.AppSettings["hpPwd"]);
                    FtpWebResponse resp = (FtpWebResponse)ftp.GetResponse();
                    Stream respStream = resp.GetResponseStream();
                    StreamReader rdr = new StreamReader(respStream);


    Now, its timing out at the StreamReader. 

    The 'navigate' variable is the IP of the scanner. 

    My assumption is that it is trying to ftp to a scanner, and therefore gets locked up. I'm not sure if the connection is actually done, but when debugging, it steps to the StreamReader before timing out.

    Does anyone have any leads on where I can take this to make it work?

    Thank you.

    Thursday, August 7, 2014 7:48 AM

Answers

  • User-417640953 posted

    Hi kaniasr,

    Welcome to asp.net forum.

    With your description and code provided, I see you want to use the FtpWebRequest to make request to ftp server

    and get some folder information from it.

    I'm not sure if the connection is actually done, but when debugging, it steps to the StreamReader before timing out.

    As for the timeout exception, I think you can try to set the Timeout and ReadWriteTimeout properties of FtpWebRequest like below.

                FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(navigate);
                ftp.Timeout = 60000;
                ftp.ReadWriteTimeout = 60000;
                ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
    ..............

    And there is an article for how to use FTPWebRequest, you can refer to below.

    http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest(v=vs.110).aspx

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 7, 2014 10:51 PM