Solved

Download from URL using proxy server and batch file

Posted on 2016-08-31
2
62 Views
Last Modified: 2016-09-07
The program below allows me to download from a URL on a proxy server.
Is it possible to do the same using a batch file?

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();

                WebProxy webProxy = new WebProxy("ftpproxy");
                WebClient client = new WebClient();
                client.Proxy = webProxy;

                //client.Proxy.Credentials = new NetworkCredential("myusername", "mypassword");
                //client.Proxy.GetProxy(new Uri("proxy.server.com:8080"));
                string Webpage = client.DownloadString("https://www.site.com/xmlfeed/xml_prices_full.asp?code=99201&user=xxx&pass=yyy");
                using (StreamWriter sw = new StreamWriter("O:\\Data_Download\\site\\SupplierFile.txt"))
                {
                    sw.Write(Webpage);
                }
                Webpage = client.DownloadString("https://www.site.com/xmlfeed/xml_prices_full.asp?code=99221&user=zzz&pass=qqq");
                using (StreamWriter sw = new StreamWriter("O:\\Data_Download\\site\\SupplierFileMBIO.txt"))
                {
                    sw.Write(Webpage);
                }

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

Open in new window

0
Comment
Question by:AlHal2
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41777708
For example with curl.exe: https://curl.haxx.se/download.html
Or with Invoke-WebRequest from Powershell.
0
 

Author Closing Comment

by:AlHal2
ID: 41787611
Thanks.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

18 Experts available now in Live!

Get 1:1 Help Now