问题描述
您好.
我想在网络环境中复制文件.针对系统(服务器)的用户名课程具有密码.
如何执行此操作.
以下示例已实现,但将出现功能不正确"错误.
请帮助我.
但是我遇到了这个异常.
当前没有可用于登录请求的登录服务器.
Hello.
I want to copy a file in my network environment. Username course against the system (server) has a password.
How do I perform this operation.
The following example has been implemented but will "Incorrect Function" error.
Please help me.
But I am getting this exception.
There are currently no logon servers available to service the logon request.
private void button3_Click(object sender, EventArgs e)
{
try
{
string _tempServerPath = Txt_ServerPath.Text + "\\" + Path.GetFileName(Txt_LocalPath.Text);
if (!File.Exists(_tempServerPath))
{
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsIdentity idnt = new WindowsIdentity(Txt_User.Text, Txt_Pass.Text);
WindowsImpersonationContext context = idnt.Impersonate();
File.Copy(Txt_LocalPath.Text, _tempServerPath);
context.Undo();
}
else
{
MessageBox.Show("specified file exists",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
catch (Exception _ex)
{
MessageBox.Show("Message :" + _ex.Message + Environment.NewLine +
"Source :" + _ex.Source + Environment.NewLine +
"Data :" + _ex.Data,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
查看图像软件和异常:
http://www.ir-win.net/images/Pic_Question_CoptFile.jpg
但是我遇到了这个异常.
当前没有可用于登录请求的登录服务器.
View Image Software and Exception:
http://www.ir-win.net/images/Pic_Question_CoptFile.jpg
But I am getting this exception.
There are currently no logon servers available to service the logon request.
推荐答案
简介
Introduction:
今天 我放了 a 样本 程序 到 管理 您的 FTP
也许 所有 您 with 许多程序 到 使用 FTP 或 拥有 看到 很多 of 您 需要 要具有 已转移 该 文件 到服务器 或 服务器 接收 和 管理 服务器 .
可以 创建 文件夹 ,管理 and 删除 文件和 文件夹 , 上传 并下载 文件 到 您的 将 .
Today I put a sample program to manage your FTP
Perhaps all of you with many programs to work with FTP or have seen much of you need to have transferred the file to the server or servers to receive and manage the server.
It can create folders, manage and delete files and folders, upload and download files to your will.
<标题=برایآشناییبامفهوم"افتیپی"href ="index.php?option = com_content& view = article& id = 222%3A--ftp-server --- xp--iis-& catid = 43%3Alearns& Itemid = 66& lang = fa>
Familiar with the concept for "FTP" and the launch method, click here
背景 :
该软件 语言 C# 2008 .
I 计划 到 已撰写 部分 of 办公自动化 和 感觉 那 ''s 太 困难 要复制 和 上传 在 网络 环境 是 完全 软件 与兼容 与 Windows 服务器 - XP 和 7 是 by 全部 FTP Microsoft 和 所有 FTP 已安装 上 the 数据中心 支持 .
Background:
The software language is written in C # 2008.
I plan to have written part of office automation and felt that''s too difficult to copy and upload in a network environment are fully software compatible with Windows Server - XP and 7 are by all FTP Microsoft and all FTP installed on the data center support.
评论 代码 :
1 - 上传文件 :
Comment code:
1 - Uploading a file:
private void Btn_UploadFTP_Click(object sender, EventArgs e)
{
string _tempServerPath = Txt_ServerPath.Text + <br /> "\\" + Path.GetFileName(Txt_LocalPath_Upload.Text);
ftPclient1.FTPclient_SetInfo(Txt_Domain.Text, Txt_User.Text, Txt_Pass.Text);
ftPclient1.Upload(Txt_LocalPath_Upload.Text, _tempServerPath);
}
public bool Upload(FileInfo fi, [Optional, DefaultParameterValue("")] string targetFilename)
{
string str;
bool _Lvr=true;
if (targetFilename.Trim() == "")
{
str = this.CurrentDirectory + fi.Name;
}
else if (targetFilename.Contains("/"))
{
str = this.AdjustDir(targetFilename);
}
else
{
str = this.CurrentDirectory + targetFilename;
}
string uRI = this.Hostname + str;
FtpWebRequest request = this.GetRequest(uRI);
request.Method = "STOR";
request.UseBinary = true;
request.ContentLength = fi.Length;
byte[] array = new byte[0x800];
using (FileStream stream = fi.OpenRead())
{
try
{
using (Stream stream2 = request.GetRequestStream())
{
int num;
do
{
num = stream.Read(array, 0, 0x800);
stream2.Write(array, 0, num);
Application.DoEvents();<br /> CountProcesses = <br /> Convert.ToInt32(<br /> Math.Round((decimal)(stream.Position * 100) / stream.Length));
ChangePerocesses_Upload();
}
while (num >= 0x800);
stream2.Close();
}
}
catch (Exception exception1)
{
_Lvr = false;
ProjectData.SetProjectError(exception1);
Exception exception = exception1;
ProjectData.ClearProjectError();
}
finally
{
stream.Close();
}
}
request = null;
UploadComplite();
return _Lvr;
}
2 - 下载 文件 :
2 - Download the file:
private void button4_Click(object sender, EventArgs e)
{
string _Source_DownloadPath = Txt_ServerPath.Text + "\\" + Txt_FileNameDownload.Text;
ftPclient1.FTPclient_SetInfo(Txt_Domain.Text, Txt_User.Text, Txt_Pass.Text);
ftPclient1.Download(_Source_DownloadPath, Txt_LocalPath_Download.Text, false);
}
3 - 显示 文件 :
3 - Display files:
private void button5_Click(object sender, EventArgs e)
{
Txt_View_FtpFile.Text = string.Empty; ;
ftPclient1.FTPclient_SetInfo(Txt_Domain.Text, Txt_User.Text, Txt_Pass.Text);
List<string> _listFile = ftPclient1.ListDirectory("//"+Txt_ServerPath.Text);
for (int i = 0; i < _listFile.Count; i++)
{
Txt_View_FtpFile.Text += _listFile[i].ToString() + Environment.NewLine;
}
}
这篇关于如何在网络环境(服务器)中复制文件,用户名密码服务器为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!