如何通过提供凭据将数据从一个位置复制到共享路径 [英] how to copy data from one one place to a shared path by giving credentials

查看:87
本文介绍了如何通过提供凭据将数据从一个位置复制到共享路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,

我需要通过登录服务器(即通过提供服务器的用户名和密码)将一个文本文件(位于本地系统中)的内容复制到另一个文本文件(位于服务器中).通过ac#代码实现这一点.有人可以帮助我吗????



i need to copy the contents of one text file (which is in my local system) to another textfile (which is in a sever) by logging into the sever(that is by giving the username and password of the server).i need to implement this through a c# code.can anyone help me in doing this????

推荐答案

可以通过unc或ftp完成.这是执行FTP操作的示例代码:

This could be done either with the unc or ftp. Here is the sample code to perform FTP operation:

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


另一种情况是,即使跨域,用户ID/密码也相同.

您所需要做的就是使用户名和密码相同,即使它们位于不同的域中,也可以使用.需要确保的是您的.NET应用程序正在以该用户身份运行.
Another scenario is same userID/password even across the domains.

All you need is for the username and password to be the same and this will work, even if they are in different domains. The thing to make sure of is that your .NET application is running as this user.


这篇关于如何通过提供凭据将数据从一个位置复制到共享路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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