Copy file from server to another

I need to copy some file from the server to another, I thought to use File.Copy , but how do I indicate the location of the file there? and there may also be a password identification from and to.

Any ideas?

+4
source share
2 answers

If these are two servers on the same local network and you have the appropriate access rights, you can probably get using the File.Copy method and transfer any path that you usually use to access the network resource in Windows Explorer (this is probably UNC path, e.g. \\TheRemoteServer\SharedFolder\MyFiles ). If you can copy the file in Explorer, the File.Copy method will be more than likely.

However, if you need to authenticate because another user on the remote server has the appropriate permissions to copy files, everything becomes a little more complicated because there is no simple .NET API for this. You can take a look at this answer to another question . Essentially, he p / calls to log on to the remote machine as another user. Once you are logged in, you can normally copy the file.

Also see this question: Accessing a shared file (UNC) from a remote, untrusted domain with credentials is a brief answer that involves using WNetUseConnection to connect to a UNC path on a remote computer with authentication.

Finally, just as a precaution, I feel that I should note that whenever you start making copies of network files, you need to be very careful to check the availability of the network path before you just blindly start copying (remote server may be unavailable, the local machine could lose network connectivity, etc.). You may also need to consider cases when the network runs out of time.

+4
source

You probably want to use FTP or SSH as a transport method to do something like this. You just need to configure the correct server-side services to use these communication methods.

Then you need a .Net library that talks about these protocols. Here is one of them:

http://www.weonlydo.com/FtpDLX.NET/ftp-sftp-ssl-net.asp

It works, but I was not so impressed with it for various reasons. I am sure there are more.

And yes, each of these protocols will query the connection system for username / password.

0
source

All Articles