Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 27th, 2008, 04:58 AM
Authorized User
 
Join Date: May 2007
Location: Hyderabad, Andhra Pradesh, India.
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

Reply With Quote
  #2 (permalink)  
Old June 27th, 2008, 05:32 AM
samjudson's Avatar
Friend of Wrox
Points: 8,448, Level: 39
Points: 8,448, Level: 39 Points: 8,448, Level: 39 Points: 8,448, Level: 39
Activity: 36%
Activity: 36% Activity: 36% Activity: 36%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,088
Thanks: 1
Thanked 181 Times in 180 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 -/
Reply With Quote
  #3 (permalink)  
Old June 27th, 2008, 06:47 AM
Authorized User
 
Join Date: May 2007
Location: Hyderabad, Andhra Pradesh, India.
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.

Reply With Quote
  #4 (permalink)  
Old June 27th, 2008, 06:57 AM
samjudson's Avatar
Friend of Wrox
Points: 8,448, Level: 39
Points: 8,448, Level: 39 Points: 8,448, Level: 39 Points: 8,448, Level: 39
Activity: 36%
Activity: 36% Activity: 36% Activity: 36%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,088
Thanks: 1
Thanked 181 Times in 180 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 -/
Reply With Quote
  #5 (permalink)  
Old June 27th, 2008, 07:50 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 05:17 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.