Link to home
Start Free TrialLog in
Avatar of janineo
janineoFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Best Method for copying files across a domain?

I'm building an ASP.NET external facing web site, which will be under SSL.
We are going to allow our users to upload files to our server via this site.

I need a method of transferring those files from the web server to our internal application server. They will be on the same domain, and possibly even physically in the same room.

What is the quickest and safest method of transferring these files from the web server to the application server, as they are uploaded - e.g not in an over night batch.

I have considered FTP and the System.IO classes. I think FTP is faster, but I'm not sure, especially via the FTPRequest class. The System.IO classes seem simpler to implement.

Can anyone offer advantages & disadvatages of each, or any other methods not mentioned?

Many Thanks,
Janine
Avatar of crazyman
crazyman
Flag of United Kingdom of Great Britain and Northern Ireland image

What sort of file sizes are we talking here...
I am not sure how you want to use FTPRequest for your scenario???

Because as I understand user file has been uploaded sucessfully and you want to copy them across to another application (which have different location). This is unnecessarily using FTP thing

The FTPRequest is faster and work better if you have a FTP server configured for downloading and uploading. But requires to configure a lot, if that webserver is behind proxy server I think you will have another problem. FTP will be helpful if you want to download and upload something especially to FTP server. And with FTPStatusCode you can see how far the process go... (you can do the same for IO)

But do you want to execute this as soon as the user finish upload or do it some where in admin page? Either case, set up some functions and call them.

If my guess is right, In your case, you better just use normal System.IO. If it is in the same host computer. IO will be perfect

Hope this helps




public string CopyNewFileToInternalServer(string newfile,string userUploadFile)
    {
        try
        {
          
            string path = Server.MapPath("D:/InternalApplication/FromUserUpload" + newfile); <-- new internal application file
            File.Copy(Server.MapPath("~/UserUpload/" + userUploadFile), path, true); //<--- this is the original file
            return path;
        }
        catch (IOException ex)
        {
            
            return "";
        }
    }

Open in new window

Avatar of janineo

ASKER

I don't think there are going to be huge - probably images from a digital compact camera, word docs, perhaps some scanned tiff files, or pdfs.

I think 2Mb would be a large file, and most would be less than 1Mb.
Avatar of janineo

ASKER

The reason I'm considering FTP is that the destination is already set up as an FTP server as that's what we use to transfer files to it from our satellite file servers. (Each office has it's own server which transfers files to the main server).

But the application that sends the files is written in VB6, so there was no access to the System.IO classes for that.

The new web server is written in .NET, so we now have the option to use System.IO.

We want to execute the transfer as soon as the file has finished uploading. The web server will probably be behind a proxy.
The host servers will be different, but quite possibly in the same rack.
Well,

You said "possibly even physically in the same room", then I guess, the new web server is located on the main server (which from before: files are transfered to from satellite servers).
And this same main server has the application server running and processing these files.
If so I think you really better use System.IO, it simplify a lot of your job.

I have used them several time and 2Mb is not a problem for your performance

Then you said: "The host servers will be different", it means the webserver and the application server are in different machine physically (I am not talking about domain). Then IO won't work. This case, FTP will be a very good option beside standard ASP.NET FileUpload control.

Then you will face quiet a lot of FTPREquest issues with Proxy but it solvable.

Hope this helps
JINN

So depend on your company request, I am sure it's changeable (howyour boss wants it) the 2 method can be useful. Either case, FTP seems to be more generic, fater, more option (not only copying file) which might be useful for future development. But it requires more configuration and research.

This link can be helpful if you want to go further with FTP:
http://www.codeproject.com/KB/dotnet/dotnetftp.aspx

FTP client library
http://www.csharphelp.com/archives/archive9.html
Avatar of janineo

ASKER

They will be in physically different boxes, with different IP addresses, but on the same domain.

When I said web server, I meant the physical server box the web site is installed on, sorry for the confusion.
We have a server room in our main office which contains all the main server boxes in racks. There is a gigabit connection between them.

The application server is a physically different box to the web server. (The application server runs the file store and the application which serves about 800 seats. There is no processing power left for the web too).

Is it not possible to use IO to transfer files across the domain? I can certainly do it with Windows Explorer, so why not with IO?

As for company requests - if I provide a compelling argument for either method, then they will go with it.

Thanks,
Janine
"Is it not possible to use IO to transfer files across the domain? I can certainly do it with Windows Explorer, so why not with IO?"

Ohh, then they are network driver. Well in that case you can perfectly use System.IO
I guess that application server where store file will have the map like Y:\UserFiles\

or share map (run from window run) like: \\MachineName\UserFiles

If this will always be the case, then you can use IO with a bit more configuration (permission so Webserver can connect and write file to that Application Server, and take care of impersonate in the web.config.
You can use System.IO namespace and UNC share path (such as \\RemoteMachineName\SharedFolder) to access the file exists in the remote server. If you do so, you also need to set proper permissions for your application on this UNC path.

File.Copy(D:\\UserUpload\data.txt, \\MachineName\UserFiles\\data.txt, true);

There will be security issues come after but this is doable.

JINN

PS: Try this:

using System;
using System.IO;
 
public class....
.....
public void TestNetworkDrives() 
    {
 
        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("Y:\\");
 
        // Get a reference to each directory in that directory.
        DirectoryInfo[] diArr = di.GetDirectories();
 
        // Display the names of the directories.
        foreach (DirectoryInfo dri in diArr)
            Response.Write(dri.Name + " <br />");
    }

Open in new window

Avatar of janineo

ASKER

Thanks for the examples.

As both methods are possible, which would you recommend for speed & security?

Thanks,
Janine
ASKER CERTIFIED SOLUTION
Avatar of jinn_hnnl
jinn_hnnl
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of janineo

ASKER

Okay, thanks for your thoughts, and the links and code examples.

I'll discuss with manager and we'll make a decision then.

Thanks,
Janine
You are welcome,
^^
Glad to help

Jinn