Solved

Download from URL on a proxy Server

Posted on 2016-08-30
3
36 Views
Last Modified: 2016-08-31
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
Comment
Question by:AlHal2
3 Comments
 
LVL 19

Accepted Solution

by:
Daniel Van Der Werken earned 250 total points
ID: 41776722
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
 
LVL 12

Assisted Solution

by:Jeff Darling
Jeff Darling earned 250 total points
ID: 41776734
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
 

Author Closing Comment

by:AlHal2
ID: 41777665
Thank you.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now