通过asp连接ftp [英] connect ftp through asp

查看:70
本文介绍了通过asp连接ftp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi ..
我是asp的新手,所以我的知识非常有限
我正在尝试使用ftpwerquest类连接到ASP服务器
此sud能够从ftp服务器访问文件,并在IE上显示文件的名称,大小,类型,时间等
如果我在机器上复制文件夹并运行代码,但是我希望编从ftp服务器获取文件夹路径...那么就无需在我的机器上复制文件夹
有可能吗?
pleaseeee hlp mw with:sigh:
与ftp类一起使用的代码是
< b>< pre lang ="xml">& lt; form method =&"POST& quot; action =&"simpleform1.asp& gt;
< br/& gt;< br/& gt;& lt; br/& lt; br/& br

< body background =& quot; C:/Documents and Settings/conference.bhopal/My Documents/My Pictures/indtextb.jpg" bgcolor =&#F5F5F5& quot; text =&#696969& quot; link =&#191970&" vlink =&#4682B4& quot; alink =&#CD5C5C& gt;"
< table border =& quot; 2& quot; cellpadding =&"3" cellspacing =&"5". width =&"100%& amp;" height =&"1& gt;"
& lt; tr& gt;
< td width =& quot; 100%& quot; colspan =&"5" height =& amp; amp; amp; amp; gt;& amp; amp; amp; amp; gt;& amp; amp; amp; amp; amp; amp; amp; quot; amp; amp; amp; quot; < img src =" C:/Documents and Settings/conference.bhopal/My Documents/My Pictures/ftp.gif" width =&"900&" height =& quot; 189& gt;</td& gt;
& lt//tr& gt;
& lt; tr& gt;
& lt; font face =& quot;旧英文文本MT& quot; color =&#005C99&" size =& quot; 5& gt;& lt; b& gt;从系统复制文件夹位置:<输入类型=&文本&" name =& quot; folderlocation& quot; /& lt; br/& gt;
& lt; br/& gt;
<输入类型=&提交&" value =&"Submit&" /& lt; br/& lt; br/& lt; br/& lt; br/& lt; br /& lt; br/& gt;
& lt;%
response.write(request.querystring(& quot; folderlocation& quot;)))
%& gt;
& lt;/form& gt;</pre>
</b>
SIMPLEFORM.ASP如下
< b>< pre lang ="xml">& lt;%
昏暗的fs,fo
设置fs = Server.CreateObject(& quot; Scripting.FileSystemObject& quot;)
设置fo = fs.GetFolder(Request.form(& quot; folderlocation& quot;)))
%& gt;
& lt; html& gt;
& lt;表格边框=&"1&"& gt;
& lt; tr bgcolor =#33ADD6& gt;
& lt; th& gt; NAME//th& gt;
& lt; th& gt; DATE& lt//th& gt;
& lt; TIME& lt//th& gt;
< th& gt;大小(字节)</th& gt;
& lt; TYPE& lt//th& gt;
& lt//tr& gt;
& lt;/html& gt;
& lt;%
昏暗的x
对于fo.files中的每个x
%& gt;

& lt; tr& gt;
< td& gt;& lt;%Response.write(x.Name)%& gt;</td& gt;
< td& gt;& lt;%response.write formatdatetime(x.datecreated,2)%& lt;/td& gt;
< td& gt;<%response.write formatdatetime(x.datecreated,3)%& lt/td&
< td& gt;<%response.write(x.size& amp; quot;字节& quot;)%& lt;/td& gt;
< td& gt;& lt;%response.write(x.type)%& lt;/td& gt;
& lt//tr& gt;
& lt;%


下一个
Response.write(& lt; br/& gt;& quot;)
昏暗y
fo.SubFolders中的每个y
response.write(& quot; SUB FOLDERS-& gt;")
Response.write(y.Name& quot;& lt; br/& gt;& quot;)
下一个
设置fo = nothing
设置fs = nothing
%& gt;/pre>
</b>

ftp程序如下

const localFile As String ="C:\ myfile.bin"
常量主机为String ="ftp://x.x.x.x./"
常量用户名As String ="******"
const密码为String ="******"
Dim URI As String =主机& amp; remoteFile
昏暗的ftp作为System.Net.FtpWebRequest = _
CType(FtpWebRequest.Create(URI),FtpWebRequest)
ftp.Credentials =新_
System.Net.NetworkCredential(用户***,密码**)
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
将响应用作System.Net.FtpWebResponse = _
CType(ftp.GetResponse,System.Net.FtpWebResponse)
使用responseStream作为IO.Stream = response.GetResponseStream

使用fs作为新的IO.FileStream(localFile,IO.FileMode.Create)
昏暗的缓冲区(2047)为字节
昏暗读取为整数= 0

读取= responseStream.Read(buffer,0,buffer.Length)
fs.Write(buffer,0,read)
循环直到读取= 0
responseStream.Close()
fs.Flush()
fs.Close()
最终使用
responseStream.Close()
最终使用
response.Close()
结束使用

hi..
m new to asp so my knowledge abt it is very limited
i m trying to connect to asp server using ftpwerquest class
this sud be able to access the files from the ftp server and display the name,size,type,time etc of the file on IE
if i copy the folder on my machine and run the code but i want the prog to take the folder path from the ftp server...so there is no need to copy the folders on my machine
is it possible???
pleaseeee hlp mw with it :sigh:
the code which works with out ftp class is
<b><pre lang="xml">&lt;form method=&quot;POST&quot; action=&quot;simpleform1.asp&quot;&gt;
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;body background=&quot;C:/Documents and Settings/conference.bhopal/My Documents/My Pictures/indtextb.jpg&quot; bgcolor=&quot;#F5F5F5&quot; text=&quot;#696969&quot; link=&quot;#191970&quot; vlink=&quot;#4682B4&quot; alink=&quot;#CD5C5C&quot;&gt;
&lt;table border=&quot;2&quot; cellpadding=&quot;3&quot; cellspacing=&quot;5&quot; width=&quot;100%&quot; height=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td width=&quot;100%&quot; colspan=&quot;5&quot; height=&quot;132&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;img src=&quot;C:/Documents and Settings/conference.bhopal/My Documents/My Pictures/ftp.gif&quot; width=&quot;900&quot; height=&quot;189&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;font face=&quot;Old English Text MT&quot; color=&quot;#005C99&quot; size=&quot;5&quot;&gt;&lt;b&gt; Copy Folder Location From The System :&lt;input type=&quot;text&quot; name=&quot;folderlocation&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;%
response.write(request.querystring(&quot;folderlocation&quot;))
%&gt;
&lt;/form&gt;</pre>
</b>
SIMPLEFORM.ASP is as follows
<b><pre lang="xml">&lt;%
Dim fs,fo
Set fs=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set fo=fs.GetFolder(Request.form(&quot;folderlocation&quot;))
%&gt;
&lt;html&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;tr bgcolor=#33ADD6&gt;
&lt;th&gt;NAME&lt;/th&gt;
&lt;th&gt;DATE&lt;/th&gt;
&lt;th&gt;TIME&lt;/th&gt;
&lt;th&gt;SIZE(bytes)&lt;/th&gt;
&lt;th&gt;TYPE&lt;/th&gt;
&lt;/tr&gt;
&lt;/html&gt;
&lt;%
dim x
for each x in fo.files
%&gt;

&lt;tr&gt;
&lt;td&gt;&lt;% Response.write (x.Name) %&gt;&lt;/td&gt;
&lt;td&gt;&lt;% response.write formatdatetime(x.datecreated,2) %&gt;&lt;/td&gt;
&lt;td&gt;&lt;% response.write formatdatetime(x.datecreated,3) %&gt;&lt;/td&gt;
&lt;td&gt;&lt;% response.write(x.size &amp; &quot; bytes&quot;) %&gt;&lt;/td&gt;
&lt;td&gt;&lt;% response.write(x.type)%&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;%


next
Response.write(&quot;&lt;br /&gt;&quot;)
dim y
for each y in fo.SubFolders
response.write(&quot;SUB FOLDERS -&gt;&quot;)
Response.write(y.Name &amp; &quot;&lt;br /&gt;&quot;)
next
set fo=nothing
set fs=nothing
%&gt;</pre>
</b>

ftp prog is as follows

Const localFile As String = "C:\myfile.bin"
Const host As String = "ftp://x.x.x.x./"
Const username As String = "******"
Const password As String = "******"
Dim URI As String = host &amp; remoteFile
Dim ftp As System.Net.FtpWebRequest = _
CType(FtpWebRequest.Create(URI), FtpWebRequest)
ftp.Credentials = New _
System.Net.NetworkCredential(user***, Password**)
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
Using response As System.Net.FtpWebResponse = _
CType(ftp.GetResponse, System.Net.FtpWebResponse)
Using responseStream As IO.Stream = response.GetResponseStream

Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0
responseStream.Close()
fs.Flush()
fs.Close()
End Using
responseStream.Close()
End Using
response.Close()
End Using

推荐答案

ASP用VBScript编写.如果您不熟悉它,请立即停止,这是一场彻底的灾难,没有人再使用它创建页面了,他们改用ASP.NEt.在ASP.NET中,您可以将任何C#或VB.NET代码用于FTP,尽管我看不出这样做的合理性.
ASP is written in VBScript. If you''re new to it, stop now, it''s an utter disaster and no-one creates pages with it anymore, they use ASP.NEt instead. In ASP.NET you can use any C# or VB.NET code for FTP, although I don''t see how it makes sense to do so.


好吧,
看起来我生活在石器时代
我得到了我的感谢,我是克里斯·吨

但是我要一个简单的ASP页面,通过它我可以访问FTP服务器并从那里检索数据并在excel中获取它

有什么办法可以使它保持简单并得到它吗?

如果没有,我

plzzz hlp !!!!!!!!!!!
oh okies
looks i m living in stone age
i got that thankZ a ton chris

but i jus wan a simple asp page through which i can access FTP server And retrieve data from there and get it in excel

is there any way i can keep it simple and get it

if not i

plzzz hlp!!!!!!!!!!!


这篇关于通过asp连接ftp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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