Transfer files from one server to another using httprequest

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(
            byte[] data = new byte[fs.Length];
            objRequest.ContentLength = data.Length;
            objRequest.ContentType = "application/x-www-form-urlencoded";
            myWriter = new StreamWriter(objRequest.GetRequestStream());
            string result = "";
            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            using (StreamReader sr =
               new StreamReader(objResponse.GetResponseStream()))
                result = sr.ReadToEnd();

My handler code is just :

public class TransportF : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
    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!!!
Who is Participating?
TechTiger007Connect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.