在服务器之间复制文件asp.net mvc [英] copy files between servers asp.net mvc

查看:142
本文介绍了在服务器之间复制文件asp.net mvc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net,c#,MVC和nHibernate,并且试图将文件从本地计算机上传到服务器,并将该文件复制到其他服务器.我能够将文件上传到服务器并将文件从一个文件夹复制到同一服务器上的另一个文件夹,没有任何问题.但是如何将文件从一个服务器复制到另一台服务器. 请点击链接以查看如何将文件从一个文件夹复制到同一服务器上的另一个文件夹. 点击以查看我对文件上传问题的回答.[请寻找kalyan的答案]

I am using asp.net, c#, MVC and nHibernate and I am trying to upload a file from a local machine to the server and replicate the file to the different server. I was able to upload file to the server and copy the file from one folder to the other folder on the same server without any problem.But how can I copy the file from one server to another server. Please follow the link to see how to copy a file from one folder to another folder on the same server. Click to see my answer to the file upload question.[please look for answer by kalyan]

请帮助.谢谢.

推荐答案

最后我明白了..这是解决我自己问题的最佳方法.
侧面说明:(以前我缺少这部分..)做任何事情之前,您应该有一个FTP站点.因此,从IIS(服务器上)创建一个FTP站点,并将根目录指向您要上载或下载的文件夹,然后从属性中手动更改用户名和密码(我的:用户名:administrator,密码:sweet123)该网站的位置(如有必要). (步骤非常简单,一旦开始创建FTP站点,您就可以轻松理解).我假设您已经准备好FTP站点.现在,我们假设该网址为 ftp://10.2.1.111/Images/.
并且不要忘记将System.Net和System.IO添加到您的名称空间.
现在从您的代码.

Finally I got it figured out.. here is the sweet code for my own problem.
Side Note:(part I was missing before..) Before you do any thing you should have a FTP site. So, from the IIS (on the server) create a FTP site and point the root directory to the folder that you want to upload or download and manually change the username and password (mine: username: administrator, password: sweet123) from the properties of the site if necessary. (steps are very simple u can easily understand once u start creating an FTP site). I assume that you have your FTP site ready. Now, let us say the url is ftp://10.2.1.111/Images/.
And dont forget to add System.Net and System.IO to your namespace.
now from your code.

        string CompleteDPath = "";
            CompleteDPath = "ftp://10.2.1.111/Images/";


            string UName = "";
            string PWD = "";
            UName = "administrator";
            PWD = "sweet123";


            WebRequest reqObj = WebRequest.Create(CompleteDPath + fname);
            reqObj.Method = WebRequestMethods.Ftp.UploadFile;
            reqObj.Credentials = new NetworkCredential(UName, PWD);
            FileStream streamObj = System.IO.File.OpenRead(_FULLlocalpathofthefile + fname);
            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;

这篇关于在服务器之间复制文件asp.net mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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