Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Download from URL using proxy server and batch file

Posted on 2016-08-31
2
Medium Priority
?
136 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 85

Accepted Solution

by:
oBdA earned 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

885 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