Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

upload a file to a different server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
carlos.zamora.quesada@gmail.com - 01 Mar 2006 18:15 GMT
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?
Simon Murrell - 02 Mar 2006 06:39 GMT
Hello Carlos

Have you set the html page to include "enctype="multipart/form-data",
e.g.
<form enctype="multipart/form-data" runat="server">

Let me know and we can try and figure it out.

Regards,
Simon

> 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.
[quoted text clipped - 31 lines]
>
> Is there anyone that can help me out how to do it?
carlos.zamora.quesada@gmail.com - 06 Mar 2006 19:59 GMT
I already try with your suggestion but it doesn't work.
I have uploaded files to the same server just doing something like
this:

HtmlInputFile fileInput;
fileInput.PostedFile.SaveAs(Server.MapPath("my_path") + "\\" +
filename);

But the issue now is that this method can't be used with a URI like the
one I'm trying to use now.
Do you have any other clue?
Patrice - 07 Mar 2006 14:05 GMT
Which URI ? Server.MapPath returns the full path name to a file. I would
write down the whole value (Server.MapPath("my_path") + "\\" + filename) to
see if it looks correct.

For now :
- either filename is not correctly initialized
- you perhaps meant Server.MapPath(my_path) instead of
Server.MapPath("my_path") ? Is this a variable in which you have the path or
do you want to save in a (sub) directory named "my_path" ?

Signature

Patrice

> I already try with your suggestion but it doesn't work.
> I have uploaded files to the same server just doing something like
[quoted text clipped - 7 lines]
> one I'm trying to use now.
> Do you have any other clue?
carlos.zamora.quesada@gmail.com - 07 Mar 2006 15:49 GMT
That's exactly what I DON'T wanna do.
I need to upload the file to a different server not to the same box.
That means that this Server.MapPath will not work because it can't work
with URI like
"http://newserver/folder/filename.ext"

I have been trying to explain that before but it seems that I couldn't.
Thanks for your answer.
carlos.zamora.quesada@gmail.com - 07 Mar 2006 18:52 GMT
Thanks guys for all your help!
I solve the issue using a different approach.
Just in case you'll like to know, I create a little HTTPRequest
application that stands on the other web server and creates the file on
it.
So I basically have a page that generates a request to another server
and the other server takes the data and creates the file.

Here is the code to create the request on C#:

string reqPage = @"http://otherWebserver/index.php";
byte[] buffer = new byte[fileInput.PostedFile.ContentLength];
fileInput.PostedFile.InputStream.Read(buffer,
0,fileInput.PostedFile.ContentLength);
WebRequest req = WebRequest.Create(reqPage);
req.Method = "POST";
req.ContentLength = buffer.Length;
req.ContentType = @"application/octet-stream";
Stream str = req.GetRequestStream();
str.Write(buffer,0,buffer.Length);
str.Close();
str.Flush();

And with this page "http://otherWebserver/index.php" I take that data
and create the file on the other server.

Thanks for all your comments!
Regards!
Patrice - 08 Mar 2006 12:28 GMT
Ok, I thought this page was already on your target server. So move the page
to the server on which you want to save the file. You'll be then able to
post to this server (from the other one)...

(of course the other option would be to use an UNC path but I suppose that
you have the problem because the other server can only be reached throught
http).

Signature

Patrice

> That's exactly what I DON'T wanna do.
> I need to upload the file to a different server not to the same box.
[quoted text clipped - 4 lines]
> I have been trying to explain that before but it seems that I couldn't.
> Thanks for your answer.
Patrice - 02 Mar 2006 09:37 GMT
If you want to use this method, there is no difference with the usual upload
with htmlInputFile. That is you POST the data to an *existing* page. This is
this server side page that will finally save the file on the server.

Signature

Patrice

> 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.
[quoted text clipped - 31 lines]
>
> Is there anyone that can help me out how to do it?
carlos.zamora.quesada@gmail.com - 06 Mar 2006 19:45 GMT
Of course there is a difference because I want to upload the file on a
different server.
This is because I can't upload anything to the actual server so I need
to use another server to upload the content.
JIC, both servers are in different domains and OS.

Regards,

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.