将文件从一个服务器传输到另一个服务器 [英] To transfer files from one server to another

查看:125
本文介绍了将文件从一个服务器传输到另一个服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将文件从一台服务器http://abc.com传输到另一台服务器http://xyz.com



我的密码是两个服务器,即http://abc.com [源服务器]和目标服务器。

How can I transfer files from one server http://abc.com to another server http://xyz.com

I do have the passwords of both servers i.e. http://abc.com [source server] and destination server.

推荐答案

因为FTP被标记,这是一种非常可接受的文件传输方法,您只需要在其中一个主机上安装FTP服务器,并且可以使用类 System.Net.FtpWebRequest 开发FTP传输的客户端部分:

http://msdn.microsoft.com/en-us/library /system.net.ftpwebrequest.aspx [ ^ ]。



(您是否还需要开发FTP的服务器端?我不喜欢你认为你需要它,但是你可以在CodeProject上找到一个合适的纯.NET库e.FTP是基于TCP的应用程序级协议,在.NET FCL中完全和原生实现,所以这也不是问题。)




可能你没有找到如何复制文件,因为你没有学习所有的请求类型:

http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.aspx [ ^ ]。



要复制文件,请使用方法 DownloadFile UploadFile



另外,你不应该忘记FTP服务器可以为不同的用户配置不同的访问权限,所以你必须采取关心正确配置。







你可以在这里找到上传代码示例:<啊REF = http://msdn.microsoft.com/en-us/library/ms229715.aspx> http://msdn.microsoft.com/en-us/library/ms229715.aspx [<一个href =http://msdn.microsoft.com/en-us/library/ms229715.aspxtarget =_ blanktitle =新窗口> ^ ]。



-SA
As FTP is tagged, which is quite an acceptable approach to the file transfer, all you need is to have FTP server on one of the hosts, and you can develop a client part of FTP transfer using the class System.Net.FtpWebRequest:
http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx[^].

(Would you need to develop the server-side of FTP as well? I don''t think you will need it, but you can find an appropriate pure .NET library on CodeProject and elsewhere. FTP is the application-level protocol over TCP, which is fully and natively implemented in .NET FCL, so this is not a problem, too.)


Probably you did not find how to copy a file, because you did not learn all the request types:
http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.aspx[^].

To copy a file, you use either the method DownloadFile or the UploadFile.

Also, you should not forget that the FTP server can configure different access privileges for different users, so you have to take care about proper configuration.



You can find the upload code sample here: http://msdn.microsoft.com/en-us/library/ms229715.aspx[^].

—SA


string CompleteDPath = "";
            CompleteDPath = "ftp://1234.1234.12.13/";


            string UName = "";
            string PWD = "";
            UName = "Administrator";
            PWD = "12345";


            WebRequest reqObj = WebRequest.Create(CompleteDPath + "abc.jpg");
            reqObj.Method = WebRequestMethods.Ftp.UploadFile;
            reqObj.Credentials = new NetworkCredential(UName, PWD);
            FileStream streamObj = System.IO.File.OpenRead(physical path + "test.jpg");
            byte[] buffer = new byte[streamObj.Length + 1];
            streamObj.Read(buffer, 0, buffer.Length);
            streamObj.Close();
            streamObj = null;
            reqObj.GetRequestStream().Write(buffer, 0, buffer.Length);
            reqObj = null;


这篇关于将文件从一个服务器传输到另一个服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆