Click here to Skip to main content
Click here to Skip to main content

How to transfer files from one webserver to another webserver

By , 8 Mar 2005
 

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

Devakumar Sai Chinthala
Founder Articledean.com & conveygreetings.com
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionThe underlying connection was closed: An unexpected error occurred on a receive.memberRajaSrirangan4 Oct '11 - 2:48 
The underlying connection was closed: An unexpected error occurred on a receive.
 
the above error i have received. can any one please tell me what kind of permission i have to give the folders?
GeneralMy vote of 1memberharsh073416 Jun '10 - 1:11 
No reason
QuestionHow to transfer Databse from offline server into online Servermemberrprabu4 Sep '07 - 4:22 
I have a MS-Sql Server 2005 Database Records in Offline Server i want to transfer the database Records into Online Server how to solve this problem
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AnswerRe: How to transfer Databse from offline server into online Server [modified]memberVerma Ankit2 Apr '10 - 2:20 
try http://blog.ankitverma.com/2010/03/onlineoffline-database-synchronization/[^]

modified on Monday, January 17, 2011 4:52 AM

Questioni got error in thismembermisterrind9 Apr '07 - 19:27 
i got the error that
 
An exception occurred during a WebClient request. help me plz
 
hi guys...

Generalfile transfering between client servermemberwafa2341912 Mar '07 - 0:01 
the previos source ican not excuete it i need only upload and download
this source ican not open it in asp.net
please help me fast
 

GeneralPlease HelpmemberLinda dsouza9 Jul '06 - 23:33 
I tried uploading a file using this code. But i m getting an error "
underlying connection was closed: unable to connect to remote server"..
Please help
 

 
Linda D'souza
QuestionGot 500 internal error ocuredmemberVipul17 Apr '06 - 3:54 
hey i am trying to use this code, but somehow it's not working. i am trying to upload images from winNT server to windwos 2003 server. i got following error.
 
"The remote server returned an error: (500) Internal Server Error"
 
please advice.
 
vipul patel
QuestionHow can i use it in aspmemberbutterfly1012 Jan '06 - 19:41 
My web application is asp code. I want to transfer file from file server(no iis) to web server. Did i can use your code to plug-in with my code. If I can how can i do it? If i can't did you have another advise for me??
 
Thank you
GeneralThank You!!!memberpunitkshah24 Nov '05 - 0:26 
Please don't consider me a spammer... I was able to upload files on a different server . Thanx a lot for posting the code.
 
Please ignore my previous mails...

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 9 Mar 2005
Article Copyright 2005 by Devakumar Sai Chinthala
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid