Solved

Transfer files from one server to another using httprequest

Posted on 2008-10-16
3
806 Views
Last Modified: 2013-12-17
I need to be able to transfer files between 2 web servers on totally different domains.  I was told that I can post a file from one server to an ashx handler on the other server using the publicly accessible URLs (and some basic authentication).  So far, all my code does is spin its wheels when


StreamWriter myWriter = null;

            HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("http://server2");
            objRequest.Method = "POST";
            FileStream fs = new FileStream(
 "\defaultsmall.jpg",FileMode.Open,FileAccess.Read);
            byte[] data = new byte[fs.Length];
            fs.Read(data,0,Convert.ToInt32(fs.Length));
            fs.Close();
            objRequest.ContentLength = data.Length;
            objRequest.ContentType = "application/x-www-form-urlencoded";
            myWriter = new StreamWriter(objRequest.GetRequestStream());
            myWriter.Write(data);
            myWriter.Close();
            string result = "";
            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            using (StreamReader sr =
               new StreamReader(objResponse.GetResponseStream()))
            {
                result = sr.ReadToEnd();
                sr.Close();
            }

My handler code is just :

public class TransportF : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        context.Response.Write("done");
           }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}


I understand that my handler code is lacking, but right now im focusing on the page that is actually trying to post the file.  Currently, it is giving me:

The request was aborted: The request was canceled. at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting) at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState) at System.Net.ConnectStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at System.IO.StreamWriter.Dispose(Boolean disposing) at System.IO.StreamWriter.Close()

when I try to close myWriter.  I know ive got a ways to go to get this to work, or maybe Im not even on the right track, but I cant seem to find any code examples that are helping.  Any advice would be greatly appreciated!!!
0
Comment
Question by:Skeletor11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 500 total points
ID: 22739087
You can do this by creating an aspx file with fileupload control in it. You can post the file to this page from the other page

Here is a sample that you can start with
http://forums.asp.net/t/1309555.aspx
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 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