如何在 ASP.Net 中使用 Server.MapPath 打开远程文本文件?
这就是我现在拥有的驻留在同一服务器上的文件,并且它可以工作。
Dim FILENAME as String = Server.MapPath("Output.txt")
Dim objStreamWriter as StreamWriter
objStreamWriter = File.CreateText(FILENAME)
dr = myCommand.ExecuteReader()
While dr.Read()
objStreamWriter.WriteLine("{0}|{1}|{2:yyyy-MM-dd}|{3:yyyy-MM-dd}", dr(0), dr(1), dr(2), dr(3))
End While
objStreamWriter.Close()
我计划完成后将文件通过 FTP 传输到另一台服务器,但有没有办法在远程服务器上执行此操作?即在远程服务器上创建一个文本文件并写入它?没有找到任何该用法的实例。在这种情况下如何使用 ServerXMLHTTP 替换 Server.MapPath ?
非常感谢您抽出时间。
This is what I have right now for a file residing on the same server and it works.
Dim FILENAME as String = Server.MapPath("Output.txt")
Dim objStreamWriter as StreamWriter
objStreamWriter = File.CreateText(FILENAME)
dr = myCommand.ExecuteReader()
While dr.Read()
objStreamWriter.WriteLine("{0}|{1}|{2:yyyy-MM-dd}|{3:yyyy-MM-dd}", dr(0), dr(1), dr(2), dr(3))
End While
objStreamWriter.Close()
I was planning on FTPing the file to another server once done but is there a way to do it on a remote server? i.e create a text file on a remote server and write to it? Did not find any instances of that usage. How to use ServerXMLHTTP to replace Server.MapPath in this instance?
Thank you so much for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以这种方式使用
MapPath
和StreamWriter
是行不通的。这适用于本地文件场景。您可以使用 FtpWebRequest 直接从 .net FTP 文件。下面是使用 FtpWebRequest 写入文件的示例(示例来自此处 ):
Using
MapPath
andStreamWriter
this way won't work. This is meant for a local file scenario. You can directly FTP files from .net using FtpWebRequest.Here's an example of using FtpWebRequest to write a file (Example from here):