Solved

Download from URL using proxy server and batch file

Posted on 2016-08-31
2
113 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Determining the an SCCM package name from the Package ID
This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

623 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