带有url的File.Copy c#

可以使用带有C#的File.Copy的两个URL吗? 我得到了不同的错误:

  1. 不支持URI格式

  2. 不支持给定路径的格式。

有一个类似的问题,但没有回答。

我希望从server1中的目录复制到另一个服务器,并且URL是http

谢谢

只有在我们不讨论FTP的情况下才能使用File.Copy。 在这种情况下,您可以使用下面的代码

如果您有FTP,可以使用以下代码:

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(); } 

那么你可以做到

 ftpfile(@"/testfolder/testfile.xml", @"c:\testfile.xml"); 

如果我们在谈论同一网络上的共享文件夹,您可以执行以下操作:

 File.Copy(filepath, "\\\\192.168.1.28\\Files"); 

对于HTTP,您可以使用以下内容:

 using(WebClient client = new WebClient()) { client.UploadFile(address, filePath); } 

资源:

使用C#通过HTTP POST发送文件

看这里: http : //msdn.microsoft.com/en-us/library/system.io.file.copy.aspx

如果你的意思是httpurl是不可能的。