Solved

Download from URL using proxy server and batch file

Posted on 2016-08-31
2
77 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i use linq for parsing string datetime to real datetime? 16 44
Keyboard 2 33
2 questions 10 25
windows 10 versions 3 33
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

806 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