- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经编写了在 ftp 中创建新站点的代码。但它给 com 异常(exception)。附上代码供引用。
异常详细信息是
System.Runtime.InteropServices.COMException was unhandled
Message="Filename: \r\nError: Unrecognized element 'ftpServer'\r\n\r\n"
Source=""
ErrorCode=-2147023483
StackTrace:
at Microsoft.Web.Administration.Interop.IAppHostElement.GetElementByName(String bstrSubName)
at Microsoft.Web.Administration.ConfigurationElement.GetChildElement(String elementName)
at WindowsFormsTest.Form2.CreateFTPSite(String serverName, String siteName, String siteID) in D:\My Projects\WindowsFormsTest\WindowsFormsTest\Form2.cs:line 48
at WindowsFormsTest.Form2.button1_Click(Object sender, EventArgs e) in D:\My Projects\WindowsFormsTest\WindowsFormsTest\Form2.cs:line 25
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsTest.Program.Main() in D:\My Projects\WindowsFormsTest\WindowsFormsTest\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
创建 ftp 站点的代码:
using(ServerManager serverManager = new ServerManager()) {
Microsoft.Web.Administration.Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
ConfigurationElement siteElement = sitesCollection.CreateElement("site");
siteElement["name"] = @"eMentorftp";
ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings");
ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");
bindingElement["protocol"] = @"ftp";
bindingElement["bindingInformation"] = @"*:21:";
bindingsCollection.Add(bindingElement);
ConfigurationElement ftpServerElement = siteElement.GetChildElement("ftpServer");
ConfigurationElement securityElement = ftpServerElement.GetChildElement("security");
ConfigurationElement sslElement = securityElement.GetChildElement("ssl");
sslElement["serverCertHash"] = @"53FC3C74A1978C734751AB7A14A3E48F70A58A84";
sslElement["controlChannelPolicy"] = @"SslRequire";
sslElement["dataChannelPolicy"] = @"SslRequire";
ConfigurationElement authenticationElement = securityElement.GetChildElement("authentication");
ConfigurationElement basicAuthenticationElement = authenticationElement.GetChildElement("basicAuthentication");
basicAuthenticationElement["enabled"] = true;
ConfigurationElementCollection siteCollection = siteElement.GetCollection();
ConfigurationElement applicationElement = siteCollection.CreateElement("application");
applicationElement["path"] = @"/";
ConfigurationElementCollection applicationCollection = applicationElement.GetCollection();
ConfigurationElement virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory");
virtualDirectoryElement["path"] = @"/";
virtualDirectoryElement["physicalPath"] = @"D:\Ftp";
applicationCollection.Add(virtualDirectoryElement);
siteCollection.Add(applicationElement);
sitesCollection.Add(siteElement);
serverManager.CommitChanges();
最佳答案
您可以从异常中判断出您的错误是什么。查看异常堆栈跟踪中的第一行:
System.Runtime.InteropServices.COMException was unhandled Message="Filename: \r\nError: Unrecognized element 'ftpServer'\r\n\r\n" Source="" ErrorCode=-2147023483
首先,我们看到“Unrecognized element 'ftpserver'”——当我们查看您的代码时,它应该告诉我们很多关于发生的事情。但除此之外,我们还提供了一个错误代码,它告诉我们抛出 COMException 的确切原因。如果我们将错误代码解码为无符号整数(十六进制),我们会得到:
0x80070585
这对应于错误代码:
有关错误代码的更多信息,请参阅 HRESULT和 Win32 error codes .
因此,我们抛出了一个 COMException,因为我们使用了无效的索引。我们在异常消息中得到了“无法识别的元素‘ftpServer’”。查看您的代码,您通过告诉 sitesCollection 添加一个名为“site”的新元素来创建一个新的 ConfigurationElement siteElement:
Microsoft.Web.Administration.Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
ConfigurationElement siteElement = sitesCollection.CreateElement("site");
然后您为站点创建一个名称,并在站点的绑定(bind)集合中创建绑定(bind):
siteElement["name"] = @"eMentorftp";
ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings");
ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");
bindingElement["protocol"] = @"ftp";
bindingElement["bindingInformation"] = @"*:21:";
bindingsCollection.Add(bindingElement);
不幸的是,您随后尝试使用名称“ftpServer”获取站点的子元素:
ConfigurationElement ftpServerElement = siteElement.GetChildElement("ftpServer");
但是,刚刚创建的 ConfigurationElement siteElement 没有名为 ftpServer 的子项!所以我们得到一个无效的索引并抛出异常。您是要在这行代码中创建一个子元素吗?
顺便说一句,我想这是一个 COMException,因为 .NET 接口(interface)与底层 IIS7 COM 对象的互操作。不是 Microsoft.Web 命名空间方面的专家(根本不是),这只是一个猜测。
关于c# - 以编程方式创建 ftp 站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4151977/
根据 FTP 协议(protocol)(rfc 959),当 ftp 客户端连接到 ftp 服务器时,应该在 ftp 客户端和 ftp 服务器之间建立控制连接。而当ftp客户端发送{LIST, R
是否可以使用 FTP 命令重命名 FTP 服务器上的文件夹? 我知道有一个用于文件重命名的 Rename 命令,但是我可以将它用于文件夹名称吗? 最佳答案 AFAIK,相同的命令( RNFR/RNTO
我有一个 ftp://host/path URL,我想下载文件并在 Erlang 中连接丢失时继续下载。 使用 ftp 开始下载非常简单模块,但如何恢复它? 最佳答案 是的..就像 Peer 提到的.
我一直在阅读 FTP 规范并使用 Wireshark 来捕获我的 FTP 客户端发送/接收的数据包,并有一些关于它们的问题。 首先是来自我的 FTP 服务器的“连接问候语”(如 FTP RFC 所称)
我有一个 ColdFusion 应用程序,用于在开发和生产服务器之间传输文件。实际发送文件的代码如下: ftp = new Ftp(); ftp.setUsername(username); ftp.
我正在尝试连接到允许匿名访问的 FTP 服务器,但我不知道如何指定执行此操作所需的适当用户名/密码。 我尝试过使用匿名/匿名作为用户/通行证,但没有成功,以及空字符串和两者的各种组合等。 这一定是我所
ftp rstatus $remotefile 在Solaris 上出现“?无效命令”错误。我发现,与 HP-UX 不同,Solaris 10 上没有像 rstatus 这样的 ftp 命令。基本上在
我是 Spring 的新手,我目前正在研究 spring 与 ftp 支持的集成。 我从本地目录传输到服务器 (filZilla)。 我从服务器下载了文件,没问题。 但我想知道如何将文件从 FTP 服
我想通过加密连接 FTP,需要使用 PHP 代码通过 TLS 隐式 FTP。 我已经尝试使用普通 FTP 进行加密,它可以工作,但加密需要通过 TLS 的隐式 FTP 不起作用。 最佳答案 尝试使用下
我已经成功使用 LuaSocket 的 TCP 工具,但我在使用它的 FTP 模块时遇到了问题。尝试检索(小)文件时,我总是超时。我可以在被动模式下使用 Firefox 或 ftp 下载文件(在 Ub
我尝试使用 putty 使用 FTP 详细信息主机名、用户名和密码登录到服务器。但是当我输入密码时它显示拒绝访问。 对于我的另一个网站,我输入了我的主机名并单击在腻子中打开,它显示“网络错误:连接超时
只是我,还是 FTP 看起来有点过时?它看起来很慢而且效率低下,而且它已经有 30 多年的历史了,并不是所有的旧东西都是坏的 :) 有哪些协议(protocol)可能成为 FTP 的继任者? 我用过一
我有一个有点相关但不同的问题 here . 我有一个批处理脚本( *.bat 文件),例如: @ftp -i -s:"%~f0"&GOTO:EOF open ftp.myhost.com myuser
我正在使用 IBM Mainframe TSO 从数据集中查看文件。最近有人告诉我每天开始将最新一代的数据集通过 FTP 传输到我桌面上的文件夹中。问题是我的 FTP 脚本只允许我用我输入的确切名称
我正在尝试使用 atom 包“Remote-FTP”和私钥连接到我的服务器。 我在我的服务器上设置了 SSH key ,并且可以使用腻子成功连接。 私钥保存在我的项目文件夹中,我有一个现有的 .ftp
我的 ftp 文件夹中有一组文件。我只能访问 ftp 模式。我想将那些扩展名为 .txt 的文件重命名为 .done 例如: 1.txt, 2.txt, 3.txt 到 1.done, 2.done,
lcd 更改本地目录。 ls 列出远程目录上的文件。 我想要的是lls,列出本地目录上的文件。 这可能吗? 我知道我总是可以打开另一个终端来执行此操作,但我很懒! 最佳答案 是的: !dir ! 告诉
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 社区去年审查
我的 FTP 测试服务器有问题。我已经安装并配置了 FileZilla 服务器,它正在监听端口 21 上的控制连接,然后它可以在 50100 和 51100 之间的端口上提供被动模式数据连接。 我正在
我正在运行 Filezilla Server 0.9.45 beta 来远程管理我的服务器。设置完成后,我测试使用 IP 127.0.0.1 连接到它,并且工作成功。但是,为了远程连接到服务器,我将端
我是一名优秀的程序员,十分优秀!