File Copy
Hello,
I want to do a small program (C#) that allows me to copy some files from one computer to another.(the computers are in the same local network).
How can I do this?
can you give me an example?
some classes that do that?
thanks

Lalit MRank #1,186 · 1.5K reputationPosted Nov 12, 2009, 8:36 PM EST
You could map a drive to the remote computer then use:
File.Copy(@"c:\myfile.txt",@"driveletter:\myfile.txt");
replacing driveletter with the letter you assigned when mapping the drive.
or you can use UNC paths:
File.Copy(@"c:\myfile.txt",@"\\machinename\c$\myfile.txt");
this would copy myfile.txt from your local C:\ drive to the remote machines C:\ drive, this would require admin permissions as it uses the C$ admin share on the remote machine.
Lalit MRank #1,186 · 1.5K reputationPosted Nov 12, 2009, 8:36 PM EST
public void ftpfile(string ftpfilepath, string inputfilepath) { string ftphost = "127.0.0.1"; //here correct hostname or IP of the ftp server to be given string ftpfullpath = "ftp://" + ftphost + ftpfilepath; FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath); ftp.Credentials = new NetworkCredential("userid", "password"); //userid and password for the ftp server to given ftp.KeepAlive = true; ftp.UseBinary = true; ftp.Method = WebRequestMethods.Ftp.UploadFile; FileStream fs = File.OpenRead(inputfilepath); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); Stream ftpstream = ftp.GetRequestStream(); ftpstream.Write(buffer, 0, buffer.Length); ftpstream.Close(); }