Click here to Skip to main content
6,822,613 members and growing! (16,129 online)
Email Password   helpLost your password?
Web Development » ASP.NET » Howto     Intermediate

How to transfer files from one webserver to another webserver

By SaidevKumar

An article which describes how to transfer files from one webserver to another webserver.
C#, Windows, .NET1.1, ASP.NET, VS.NET2003, Dev
Posted:8 Mar 2005
Views:58,315
Bookmarked:44 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
17 votes for this article.
Popularity: 4.10 Rating: 3.33 out of 5
5 votes, 29.4%
1

2
1 vote, 5.9%
3
5 votes, 29.4%
4
6 votes, 35.3%
5

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.

//

// 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

About the Author

SaidevKumar


Member

Occupation: Architect
Company: aAmbit Inc
Location: United States United States

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 12 of 12 (Total in Forum: 12) (Refresh)FirstPrevNext
QuestionHow to transfer Databse from offline server into online Server Pinmemberrprabu5:22 4 Sep '07  
Questioni got error in this Pinmembermisterrind20:27 9 Apr '07  
Generalfile transfering between client server Pinmemberwafa234191:01 12 Mar '07  
GeneralPlease Help PinmemberLinda dsouza0:33 10 Jul '06  
QuestionGot 500 internal error ocured PinmemberVipul4:54 17 Apr '06  
GeneralHow can i use it in asp Pinmemberbutterfly10120:41 2 Jan '06  
GeneralThank You!!! Pinmemberpunitkshah1:26 24 Nov '05  
GeneralAre only doc files allowed Pinmemberpunitkshah22:21 23 Nov '05  
GeneralHelp!!! Pinmemberpunitkshah21:07 23 Nov '05  
Generalhow can i transfer files from one server to other server directly? Pinmembernju761:15 8 Sep '05  
GeneralDont repost Pinmemberleppie0:38 9 Mar '05  
GeneralAttempt failed to Upload PinmemberKishore P. Krishna22:22 19 Jul '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 8 Mar 2005
Editor: Smitha Vijayan
Copyright 2005 by SaidevKumar
Everything else Copyright © CodeProject, 1999-2010
Web19 | Advertise on the Code Project