|
-
Apr 28th, 2006, 12:04 PM
#1
[2005] Getting list of files from a folder (FTP) [Urgent :(]
Hello!
Im making a software for our Counter-Strike Source server.
I'd like to get all map files (.bsp files) from the map folder using the servers ftp adress.
I tried using this code:
VB Code:
Dim folder As New IO.DirectoryInfo(ftpAdress & "/srcds_l/cstrike/maps/")
Dim files As IO.FileInfo() = folder.GetFiles("*.bsp")
But it gives me the error "The given path's format is not supported."
So what should I do? Any suggestions?
Thanks in advance.
Last edited by Atheist; Apr 28th, 2006 at 05:08 PM.
-
Apr 28th, 2006, 12:43 PM
#2
Fanatic Member
Re: [2005] Getting list of files from a folder (FTP)
DirectoryInfo doesn't in fact support ftp type addresses. If you're still on .NET 2003 you'll have either have to shell the windows ftp utility or write your own warpper to the windows calls. I think .NET 2005 has the ftpWebRequest class in the System.Net or System.Web namespace
Last edited by Mr.No; Apr 28th, 2006 at 12:47 PM.
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Apr 28th, 2006, 12:51 PM
#3
Re: [2005] Getting list of files from a folder (FTP)
ftpWebRequest...yeah ive seen that when i was havin a look around.
Could you help me on how to use it?
-
Apr 28th, 2006, 01:10 PM
#4
Fanatic Member
Re: [2005] Getting list of files from a folder (FTP)
Could you help me on how to use
Unfortunately no, I' still using VB.NET 2003 and haven't tried the ftpWebreqtest thing, I just read about its existence ..
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Apr 28th, 2006, 03:00 PM
#5
Re: [2005] Getting list of files from a folder (FTP)
ok...thanks anyways, I'll give it a good look.
-
Apr 29th, 2006, 02:52 AM
#6
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
you need to use WebRequestMethods.Ftp.ListDirectoryDetails to list the contents of an ftp directory.
a quick example i put together ....
VB Code:
[COLOR=Blue]Private Sub[/COLOR] Button1_Click([COLOR=Blue]ByVal[/COLOR] sender [COLOR=Blue]As[/COLOR] System.Object, [COLOR=Blue]ByVal[/COLOR] e [COLOR=Blue]As[/COLOR] System.EventArgs) [COLOR=Blue]Handles[/COLOR] Button1.Click
[COLOR=Blue]Dim[/COLOR] ftp [COLOR=Blue]As[/COLOR] FtpWebRequest = [COLOR=Blue]DirectCast[/COLOR](FtpWebRequest.Create("ftp://mirror.nl/disk2/tucows/"), FtpWebRequest)
[COLOR=Green]'/// ************************
'///NOTE if you need to authenticate with username / password you would add the following 2 lines ...[/COLOR]
[COLOR=Green]'Dim cred As New NetworkCredential("username here", "password here")
'ftp.Credentials = cred
'/// ************************[/COLOR]
ftp.AuthenticationLevel = Security.AuthenticationLevel.MutualAuthRequested
ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails
ftp.Proxy = [COLOR=Blue]Nothing[/COLOR]
[COLOR=Blue]Dim[/COLOR] ftpresp [COLOR=Blue]As[/COLOR] FtpWebResponse = [COLOR=Blue]DirectCast[/COLOR](ftp.GetResponse, FtpWebResponse)
'/// **** these 3 lines are NOT needed, just shows you a bit of the server logon messages you would see ...
Console.WriteLine(ftp.Headers.ToString)
Console.WriteLine(ftpresp.BannerMessage)
Console.WriteLine(ftpresp.Headers.ToString)
'/// ****
[COLOR=Blue]Dim[/COLOR] sreader [COLOR=Blue]As New[/COLOR] IO.StreamReader(ftpresp.GetResponseStream)
[COLOR=Blue]While Not[/COLOR] sreader.Peek = -1
[COLOR=Blue]Dim[/COLOR] ftpList [COLOR=Blue]As String[/COLOR]() = sreader.ReadLine.Split(" ")
[COLOR=Blue]Dim[/COLOR] ftpfile [COLOR=Blue]As String[/COLOR] = ftpList(ftpList.GetUpperBound(0))
Console.WriteLine(ftpfile)
[COLOR=Blue]End While[/COLOR]
ftpresp.Close()
[COLOR=Blue]End Sub[/COLOR]
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Apr 29th, 2006, 03:14 AM
#7
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
Thank you ALOT mate! You cant imagine how much i needed that code
-
Apr 29th, 2006, 04:57 AM
#8
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
Just one more thing:
I had this code you gave me the click event of a button.
I tried clicking the button several times with a small pause between each click and then this error message came popping up:
The remote server returned an error: (500) Syntax error, command unrecognized.
On the line marked in red:
VB Code:
Dim ftp As FtpWebRequest = DirectCast(FtpWebRequest.Create(ftpAdress & "/srcds_l/cstrike/maps/"), FtpWebRequest)
'/// ************************
'///NOTE if you need to authenticate with username / password you would add the following 2 lines ...
'Dim cred As New NetworkCredential("username here", "password here")
'ftp.Credentials = cred
'/// ************************
ftp.AuthenticationLevel = Security.AuthenticationLevel.MutualAuthRequested
ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails
ftp.Proxy = Nothing
[COLOR=Red]Dim ftpresp As FtpWebResponse = DirectCast(ftp.GetResponse, FtpWebResponse)[/COLOR]
'/// **** these 3 lines are NOT needed, just shows you a bit of the server logon messages you would see ...
Console.WriteLine(ftp.Headers.ToString)
Console.WriteLine(ftpresp.BannerMessage)
Console.WriteLine(ftpresp.Headers.ToString)
'/// ****
Dim sreader As New IO.StreamReader(ftpresp.GetResponseStream)
While Not sreader.Peek = -1
Dim ftpList As String() = sreader.ReadLine.Split(" ")
Dim ftpfile As String = ftpList(ftpList.GetUpperBound(0))
Console.WriteLine(ftpfile)
If ftpfile.Contains(".bsp") And Not ftpfile.Contains(".ztmp") Then
lwMaps.Items.Add(ftpfile, 6)
End If
End While
ftpresp.Close()
-
Apr 29th, 2006, 05:31 AM
#9
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
well you should only click one time. but, is the ftp path remote? or local?
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Apr 29th, 2006, 05:41 AM
#10
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
Its remote.
I have an option in a menu "Server maps", when its clicked it fires this code and lists all the maps, so it can be clicked several times
-
Apr 29th, 2006, 07:05 AM
#11
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
make sure your ftp path is correct , it must be ftp://server path.com , NOT ftp://ftp.server path.com
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Apr 29th, 2006, 10:30 AM
#12
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
-
Apr 29th, 2006, 10:50 AM
#13
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
hmm I just changed the line:
VB Code:
Dim ftpresp As FtpWebResponse = DirectCast(ftp.GetResponse, FtpWebResponse)
to:
VB Code:
Dim ftpresp As FtpWebResponse
Try
ftpresp = DirectCast(ftp.GetResponse, FtpWebResponse)
Catch ex As Exception
MsgBox(ex.Message)
End Try
And now its working as it should. No error messages at all.
-
Apr 29th, 2006, 10:51 AM
#14
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
But I'd like to ask you one more thing while im still at it...
Do you know how to erase a file on the ftp server?
Very much appreciated. Thank you.
-
Apr 29th, 2006, 11:33 AM
#15
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
you would use WebRequestMethods.Ftp.DeleteFile when doing the FtpWebrequest
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Apr 29th, 2006, 11:39 AM
#16
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
yeah i saw that there was something in there that looked good. But how do I use it?
-
Apr 29th, 2006, 11:43 AM
#17
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
specify the file you want in the request, eg
FtpWebRequest.Create(ftpAdress & "/srcds_l/cstrike/maps/somefile.exe")
the method ...
ftp.Method = WebRequestMethods.Ftp.DeleteFile
just use the same routine as getting the list.
but ...
you must have permission to delete the file.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Apr 29th, 2006, 11:54 AM
#18
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
aaah I understand. Yeah Ive got permission. Thank you alot youve made my day
-
Apr 30th, 2006, 05:56 AM
#19
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
Still getting those error messages i mentioned in previous posts...It looks to me like its the server being a b*tch..
-
Nov 29th, 2006, 01:27 PM
#20
Hyperactive Member
Re: [2005] Getting list of files from a folder (FTP) [Urgent :(]
I know this is an old thread, but I just ran across this while trying to do something along the same lines (I needed to make an app that would check this ftp site every day and make sure a certain file was there (because it gets automatically ftp'd)).
When looping through the contents of the FTP site (and using this code), it would throw an error after returning about 20 items in the folder, saying 550: File not Found.
If you cange:
VB Code:
While Not sreader.Peek = -1
Dim ftpList As String() = sreader.ReadLine.Split(" ")
Dim ftpfile As String = ftpList(ftpList.GetUpperBound(0))
Console.WriteLine(ftpfile)
End While
to:
VB Code:
Do Until sreader.EndOfStream
ftpList = sreader.ReadLine.Split(" ")
ftpfile = ftpList(ftpList.GetUpperBound(0))
Console.WriteLine(ftpfile)
Loop
Then it returns all items, atleast for me.
Just posting this, incase someone else comes across this thread and has the same problem I did. Pretty simple fix, actually.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|