Upload files using asp.net

There is a data file and some image files that I have to upload to our local servers every night using asp.net. What is the best way to do this?

UPDATE

Well, after looking at the answers, I see that my initial post using asp.net is a bad choice. How could you write it for a console application in C #. I am not sure which classes I use to connect and pull files from a remote server.

thanks

+3
source share
6 answers

"How could you write it for a console application in C #."

#. System.Net.


using System;
using System.Net;

namespace Downloader
{
    class Program
    {
        public static void Main(string[] args)
        {
            using (WebClient wc = new WebClient())
            {
                wc.DownloadFile("http://www.mydomain.com/resource.img", "c:\\savedImage.img");
            }
        }
    }
}
+9

URL-, WebClient # System.Net.

FileResult ( )       {

        WebClient client = new WebClient();
        var stream = client.OpenRead("http://www.jplayer.org/audio/mp3/Miaow-03-Lentement.mp3");

        return File(stream, "audio/mpeg");

    }

. http://www.quartz-scheduler.net/

+1

, , - asp.net, .

ASP.NET .

0

DownloadFile System.Net.WebClient, , . URL , - . System.NET.WebClient MSDN

You can even customize user agent user strings and upload files using this class.

0
source

If you cannot do this using FTP, you want to use HttpWebRequest and HttpWebResponse to complete the job. From MSDN :

using System;
using System.Net;
using System.Text;
using System.IO;


    public class Test
    {
        // Specify the URL to receive the request.
        public static void Main (string[] args)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);

            // Set some reasonable limits on resources used by this request
            request.MaximumAutomaticRedirections = 4;
            request.MaximumResponseHeadersLength = 4;
            // Set credentials to use for this request.
            request.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse ();

            Console.WriteLine ("Content length is {0}", response.ContentLength);
            Console.WriteLine ("Content type is {0}", response.ContentType);

            // Get the stream associated with the response.
            Stream receiveStream = response.GetResponseStream ();

            // Pipes the stream to a higher level stream reader with the required encoding format. 
            StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);

            Console.WriteLine ("Response stream received.");
            Console.WriteLine (readStream.ReadToEnd ());
            response.Close ();
            readStream.Close ();
        }
    }

/*
The output from this example will vary depending on the value passed into Main 
but will be similar to the following:

Content length is 1542
Content type is text/html; charset=utf-8
Response stream received.
<html>
...
</html>

*/
0
source

All Articles