Nathan
Nathan

Reputation: 25006

upload files to a different server

My web applications are on Server D. So I created a web application that has an fileupload control. I can easily upload any file to a folder (FILES) inside the web app.

My question now: How can I upload the same file (from code behind) to a folder (UPLOADS) on a different server (SERVER T) that I have? I also need to read,write and modify that file on the SERVER T. Remember that I use Web Forms and not Windows Forms!!!

Someone told me something about creating a Network Service account on server T for the web app on server D to use and give that account permissions or something like that but he doesn’t know the details either.

Is there a tutorial, guide since I'm sure there is a way to do this…

Also, all I can find on Google is using ftp but for windows forms only…

Kinda stuck around here…

Upvotes: 2

Views: 7813

Answers (3)

Yahya
Yahya

Reputation: 3444

Taken from this blog post

We can do following-

  1. Login to a user account using c#
  2. Impersonate as the logged in user
  3. Copy the file using System.IO.File.Copy

Upvotes: 2

Kaf
Kaf

Reputation: 33809

If you need to read/write/change files in a network folder, you can try this:

Open IIS > Application Pools 
            > Select Application pool of the site
              > Advanced Options
                > Process Model > Select Identity

Now you should know the Application Pool Account. Finally make sure that account does have the required privileges to SERVER T\UPLOADS folder.

Upvotes: 2

Bob The Janitor
Bob The Janitor

Reputation: 20792

A very simple solution would be to simply ftp the file to the new server, here is an example

http://www.codeproject.com/Articles/343913/Simple-FTP-library-in-Csharp

or doing an http post to the other server here is a SO question with a decent answer for doing that

FileUpload to FileStream

once the file is on the other server push the work of update/modify/etc to the other server

Upvotes: 0

Related Questions