• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 79
  • Last Modified:

Download from URL on a proxy Server

The code below works on my local machine.  However to connect to external websites on the production server, I have to set the hostname to ftpProxy.

Example:

On the old server I would use these credentials.

set HOSTNAME=ftp.site.com
set USERID=user
set PWD=yyy

On the new server I would use these.

set HOSTNAME=ftpproxy
set USERID=user@ftp.site.com
set PWD=yyy

How do I get this to work on the production server?  I'm using a C# windows form program.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace WebDownloader
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                WebClient client = new WebClient();
                string Webpage = client.DownloadString("https://www.Site.com/xmlfeed/xml_prices_full.asp?code=99201&user=xxxml&pass=yy");
                using (StreamWriter sw = new StreamWriter("O:\\Data_Download\\Supplier\\SupplierFile.txt"))
                {
                    sw.Write(Webpage);
                }
                Webpage = client.DownloadString("https://www.Site.com/xmlfeed/xml_prices_full.asp?code=99221&user=xxxml&pass=yy");
                using (StreamWriter sw = new StreamWriter("O:\\Data_Download\\Supplier\\SupplierFileMBIO.txt"))
                {
                    sw.Write(Webpage);
                }

                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                using (StreamWriter sw2 = new StreamWriter("O:\\Loaders\\Global\\Supplier\\Commodities\\Price\\Errors\\DownloadError.txt"))
                {
                    sw2.Write(ex.Message);
                    
                }
                Environment.Exit(1);
            }
        }
    }
}

Open in new window

0
AlHal2
Asked:
AlHal2
2 Solutions
 
Daniel Van Der WerkenIndependent ConsultantCommented:
I recommend you trying this.

using System.Net;
            WebProxy webProxy = new WebProxy("http://10.1.1.1:8080");
            WebClient wClient = new WebClient();
            wClient.Proxy = webProxy;

Open in new window


Where http://10.1.1.1:8080 is the address of the proxy.

Then try to authenticate again the same way you are. You may have to try both ways.
1
 
Jeff DarlingDeveloper AnalystCommented:
To supply the username/password for the proxy

                client.Proxy.Credentials = new NetworkCredential("myusername", "mypassword");
                client.Proxy.GetProxy(new Uri("proxy.server.com:8080"));

Open in new window

1
 
AlHal2Author Commented:
Thank you.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now