Microsoft
Software
Hardware
Network
Question : 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("
h
ttp://serv
er2
");
objRequest.Method = "POST";
FileStream fs = new FileStream(
"\defaultsmall.jpg",FileMo
de.Open,Fi
leAccess.R
ead);
byte[] data = new byte[fs.Length];
fs.Read(data,0,Convert.ToI
nt32(fs.Le
ngth));
fs.Close();
objRequest.ContentLength = data.Length;
objRequest.ContentType = "application/x-www-form-ur
lencoded";
myWriter = new StreamWriter(objRequest.Ge
tRequestSt
ream());
myWriter.Write(data);
myWriter.Close();
string result = "";
HttpWebResponse objResponse = (HttpWebResponse)objReques
t.GetRespo
nse();
using (StreamReader sr =
new StreamReader(objResponse.G
etResponse
Stream()))
{
result = sr.ReadToEnd();
sr.Close();
}
My handler code is just :
public class TransportF : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.Write("do
ne");
}
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.C
loseIntern
al(Boolean
internalCall, Boolean aborting) at System.Net.ConnectStream.S
ystem.Net.
ICloseEx.C
loseEx(Clo
seExState closeState) at System.Net.ConnectStream.D
ispose(Boo
lean disposing) at System.IO.Stream.Close() at System.IO.StreamWriter.Dis
pose(Boole
an disposing) at System.IO.StreamWriter.Clo
se()
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!!!
Answer : Transfer files from one server to another using httprequest
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
Random Solutions
How to change gradually by code the forecolor of a Progressbar ?ex:from green to yellow
One way traffic over a hardware VPN
mqsvc.exe has generated errors - message at startup - what does it mean and why etc.?
Bad email locks up Outlook Express, can't move or delete
Export table to another Access DB
I want to hyperlink a image in pdf using vb.net code using iTextSharp.text and Imports iTextSharp.text.pdf class
nVidia nForce Raid controller embedded in Proliant ML115 G5 Event 129
how can I compare two databases in foxpro to check if they are identical?
Permanently remove review tracking?
Deletion of record - But HOW ? Very odd.