Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2008, 04:58 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default uploading file to a remote IP using upload control

Hi All

I want to upload file to a remote server. Currently i am using this code:

 protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (fupInProc.HasFile)
        {
            fupInProc.SaveAs(Server.MapPath("documents\\" + fupInProc.FileName));
            lblUpload.Text = "File Uploaded:" + fupInProc.FileName;
        }
        else
        {
            lblUpload.Text = "No File Uploaded";
        }


Please tell me how to give the address of server along with UserID and PWD in the path.
Say if IP is 192.168.0.1

 
Old June 27th, 2008, 05:32 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

When you say 'upload' what do you mean? If you just want to save the file to a different server on the same network then just create a share on that server and save it directly:

fupInProc.SaveAs(@"\\192.168.0.1\DocShare\" + fupInProc.FileName);

If you mean some other method of transfer then please say exactly how you would like to transfer the document.

/- Sam Judson : Wrox Technical Editor -/
 
Old June 27th, 2008, 06:47 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

yes, i just want to save the file to a different server on the same network but one thing is intriguing me is that if a create a 'share' folder,would it not be a securtiy risk?(I may be wrong) Is there any way to give user name and password for that particular server in save as.

 
Old June 27th, 2008, 06:57 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

It would only be insecure if you didn't implement any security, or let 'Everyone' read and write to the share.

You can restrict security to the 'user' which is running your web site, I forget what this default to, either Network Service, or ASP.Net.

/- Sam Judson : Wrox Technical Editor -/
 
Old June 27th, 2008, 07:50 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Getting a web app to talk to the local file system is hard enough. Getting it to talk to (and certainly to write files) to a networked system is even more difficult.

The initial problem is that the security context that the site runs as is a local one. To complicate things, the security context changes as you progress through the life of an ASP.NET web request. The IIS service, as Sam suggested, typically runs as "Network Service". However, you can set a particular site or virtual directory to run under another user. Furthermore, you can configure ASP.NET to impersonate yet another user. So it can be very difficult to figure out exactly "who" it is that is doing some action against the file system.

As I mentioned, the user context for these processes are local ones. In order to successfully access a network share you'll need to run your site and possibly processes as domain accounts in order to get security contexts between machines that will cooperate. Of course, this then also requires both machines being members of the same or trusted domains.

One solution may be to create a virtual directory in the site you are trying to do this in. That virtual directory will point to the network location you wish to save files to. When you set it up you can specify what user to connect as, and in this case you can specify an external user context, such as a local account from the other machine (MACHINENAME\USER). This would likely be a bit more secure that modifying the IIS sites or process. When you save files, you'll just save them to a "local" virtual path such as /mysite/myMappedVirtualDir.

Unfortunately, setting up things like this typically becomes trial-and-error. You have to just keep trying different things until it works. It is understandable that web site technologies adhere to the principle of least privilege, but it often gets in the way of simply getting things done.

-Peter
compiledthoughts.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
file upload control iamsunil2006 .NET Framework 2.0 1 January 21st, 2008 05:49 AM
File Upload to Remote Server - - - Please Help sendoh11 ASP.NET 1.0 and 1.1 Professional 4 December 26th, 2006 10:29 AM
File Upload control MunishBhatia ASP.NET 2.0 Professional 1 December 6th, 2006 03:33 AM
Create/Upload a file on a Remote Machine SmboInc C# 2 November 20th, 2006 12:42 PM
Upload file into a Remote Server swaminathanb Java GUI 2 April 7th, 2005 02:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.