Click here to Skip to main content
15,881,380 members
Articles / Web Development / ASP.NET
Article

How to transfer files from one webserver to another webserver

Rate me:
Please Sign up or sign in to vote.
3.41/5 (21 votes)
8 Mar 20051 min read 116K   2.7K   53   16
An article which describes how to transfer files from one webserver to another webserver.

Screen Shot of Download file screen

Introduction

This article describes about a common requirement of transferring files from one web server to another web server.

Background

When I was working in some project, there was a requirement where I had a web application (http://someserver/someapplication) from where I had to transfer the files to another web server (http://www.someotherserver/someotherapplication). So, I thought why should not I share the same with you all.

Using the code

Download the WebRequest project and WebRequestReceiver project. Install it in a convenient location, e.g.: c:\inetpub\wwwroot. The ZIP file contains both projects.

This article has two projects:

  1. A main project which contains the code to upload/download files.
    1. To transfer/upload a file from one webserver to another webserver (frmUploadFile.aspx).
    2. To retrieve/download a file from the other webserver to the location machine (frmDownloadFile.aspx).
  2. A Web Request Receiver project which will save the files that are posted to it.

The application makes use of the WebClient class provided in the .NET framework.

C#
//
// For uploading the file
//
try
{ 
    WebClient oclient = new WebClient(); 
    byte[] responseArray = 
       oclient.UploadFile(txtURLToSend.Text,"POST",txtFileToSend.Text); 
    lblStatus.Text = 
       "Check the file at " + Encoding.ASCII.GetString(responseArray); 
} 
catch (Exception ex) 
{ 
    lblStatus.Text = ex.Message;
}

//
// For downloading the file
//
try
{
    WebClient oclient = new WebClient();
    oclient.DownloadFile(txtURL.Text,txtFileLocation.Text);
    lblStatus.Text = "Check the file at " + txtFileLocation.Text;
}
catch (Exception ex)
{
    lblStatus.Text = ex.Message;
}

When I say uploading the file from one web server to another web server, it basically posts the file from one web server to another web server like the way a file from the client side is posted when you use <input type="file">.

Points of Interest

This example is useful in places where you have to post files from one web server to another web server.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Founder Articledean.com & conveygreetings.com
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThe underlying connection was closed: An unexpected error occurred on a receive. Pin
RajaSrirangan4-Oct-11 2:48
RajaSrirangan4-Oct-11 2:48 
GeneralMy vote of 1 Pin
harsh073416-Jun-10 1:11
harsh073416-Jun-10 1:11 
QuestionHow to transfer Databse from offline server into online Server Pin
rprabu4-Sep-07 4:22
rprabu4-Sep-07 4:22 
AnswerRe: How to transfer Databse from offline server into online Server [modified] Pin
Verma Ankit2-Apr-10 2:20
Verma Ankit2-Apr-10 2:20 
Questioni got error in this Pin
misterrind9-Apr-07 19:27
misterrind9-Apr-07 19:27 
Generalfile transfering between client server Pin
wafa2341912-Mar-07 0:01
wafa2341912-Mar-07 0:01 
GeneralPlease Help Pin
Linda dsouza9-Jul-06 23:33
Linda dsouza9-Jul-06 23:33 
QuestionGot 500 internal error ocured Pin
Vipul17-Apr-06 3:54
Vipul17-Apr-06 3:54 
QuestionHow can i use it in asp Pin
butterfly1012-Jan-06 19:41
butterfly1012-Jan-06 19:41 
GeneralThank You!!! Pin
punitkshah24-Nov-05 0:26
punitkshah24-Nov-05 0:26 
GeneralRe: Thank You!!! Pin
DRKARTHIKRAJ22-May-12 20:10
DRKARTHIKRAJ22-May-12 20:10 
GeneralAre only doc files allowed Pin
punitkshah23-Nov-05 21:21
punitkshah23-Nov-05 21:21 
GeneralHelp!!! Pin
punitkshah23-Nov-05 20:07
punitkshah23-Nov-05 20:07 
Questionhow can i transfer files from one server to other server directly? Pin
Member 22521508-Sep-05 0:15
Member 22521508-Sep-05 0:15 
GeneralDont repost Pin
leppie8-Mar-05 23:38
leppie8-Mar-05 23:38 
GeneralAttempt failed to Upload Pin
Kishore P. Krishna19-Jul-05 21:22
Kishore P. Krishna19-Jul-05 21:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.