Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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.
 
Share this answer
 
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!!!!!!!!!!!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900