C
carlos.zamora.quesada
Hey guys I'm trying to upload a file from one server to another I have
been trying several ways but I'm still not getting the results I want.
Basically I have the HtmlInputFile component and I have read the file
using:
HtmlInputFile fileInput;
byte[] buffer = new byte[fileInput.PostedFile.ContentLength];
fileInput.PostedFile.InputStream.Read(buffer, 0, buffer.Length);
After that I want to upload the file to a different server using:
string targetFileName = "http://otherwebsite.net/tmp/new.file";
System.Net.WebClient client = new System.Net.WebClient();
client.UploadData(targetFileName, buffer);
But this doesn't create the file on the other server. That folder on
the other server has full write permissions
I try also adding credentials to the webclient component.
client.Credentials = new System.Net.NetworkCredential("user", "pass");
I have been reading a lot of things about it but I'm still can't
find the way to create such file.
Already try:
WebRequest req = WebRequest.Create(targetFileName);
req.Method = "POST";
req.ContentLength = buffer.Length;
req.ContentType = fileInput.PostedFile.ContentType;
Stream str = req.GetRequestStream();
str.Write(buffer,0,buffer.Length);
str.Flush();
str.Close();
But nothing seems to be working.
Is there anyone that can help me out how to do it?
been trying several ways but I'm still not getting the results I want.
Basically I have the HtmlInputFile component and I have read the file
using:
HtmlInputFile fileInput;
byte[] buffer = new byte[fileInput.PostedFile.ContentLength];
fileInput.PostedFile.InputStream.Read(buffer, 0, buffer.Length);
After that I want to upload the file to a different server using:
string targetFileName = "http://otherwebsite.net/tmp/new.file";
System.Net.WebClient client = new System.Net.WebClient();
client.UploadData(targetFileName, buffer);
But this doesn't create the file on the other server. That folder on
the other server has full write permissions
I try also adding credentials to the webclient component.
client.Credentials = new System.Net.NetworkCredential("user", "pass");
I have been reading a lot of things about it but I'm still can't
find the way to create such file.
Already try:
WebRequest req = WebRequest.Create(targetFileName);
req.Method = "POST";
req.ContentLength = buffer.Length;
req.ContentType = fileInput.PostedFile.ContentType;
Stream str = req.GetRequestStream();
str.Write(buffer,0,buffer.Length);
str.Flush();
str.Close();
But nothing seems to be working.
Is there anyone that can help me out how to do it?