FTP Details

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
6 posts Page 1 of 1
Contributors
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

FTP Details
M1z23R
I'll teach you how to list folders with some multiple info, like file date/size/permissions on ftp (read/write).

Add listview to your form and set it's view to details.
Add 4 columns - "File Name", "Size", "Date" and "Permissions" it is column title.

Now add GET button or refresh, name it whatever you want, and add this code.

Code: Select all

 
     Dim ftpClient As System.Net.FtpWebRequest = CType(Net.WebRequest.Create("ftp://HOST/Folder"), Net.FtpWebRequest)'Must include ftp:// in front
            ListView1.Items.Clear()
            ftpClient.Method = Net.WebRequestMethods.Ftp.ListDirectoryDetails
            ftpClient.Credentials = New Net.NetworkCredential("username", "password")
            Dim ftpClientResponse As Net.FtpWebResponse = CType(ftpClient.GetResponse(), Net.FtpWebResponse)
            Dim ftpStream As IO.Stream = ftpClientResponse.GetResponseStream()
            Dim ftpStreamReader As New IO.StreamReader(ftpStream)
            For Each iFile As String In ftpStreamReader.ReadToEnd.Split(vbCrLf)
                If iFile <> "" Then
                    While iFile.Contains("  ")
                        iFile = iFile.Replace("  ", " ") 'It is some crazy format, so i do this to reformat it so i can split that string 
                    End While

                    Dim lvi As New ListViewItem
                    Dim fileString() = iFile.Split(" ")'Splitting and getting Collection

                        For i As Integer = 8 To fileString.Length - 1
                        lvi.Text += fileString(i) + " " 'Name - (+ " ") returns the space that was used to split string
                    Next
                    lvi.Text = lvi.Text.Substring(0, lvi.Text.Length - 1)'Removes space at the end of list view item's text.
'It should be just 8, but if your file/folder has spaces in it it will get first word only.
                    lvi.SubItems.Add(fileString(4)) 'Size
                    lvi.SubItems.Add(fileString(5) + "-" + fileString(6) + "-" + fileString(7)) 'Date
                    lvi.SubItems.Add(fileString(0)) 'Permissions
                    ListView1.Items.Add(lvi)
                End If
            Next
        Catch ex As Exception
        End Try
I hope you like it, i added info about functions inside the code.


*************************** EDIT ***************************

So, I've decided to upload the whole project, with 'back' function, and navigation through the folders. Ability to download/upload files, and make new folder.
You do not have the required permissions to view the files attached to this post.
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: FTP Details
M1z23R
Update, now can make difference between files and folders. Those that downloaded - pm me you'll get source for free.
You do not have the required permissions to view the files attached to this post.
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: FTP Details
XTechVB
using FtpWebRequest is very easy to access a ftp server but you need to login every time you do an operation like renaming, uploading, folder/file creation, deletion etc.
You can find me on Facebook or on Skype mihai_92b
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: FTP Details
XTechVB
i'm making a ftp client but i cant find a way to delete a folder and all the other folders and sub-folders within it
You can find me on Facebook or on Skype mihai_92b
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Re: FTP Details
Codex
XTechVB wrote:
i'm making a ftp client but i cant find a way to delete a folder and all the other folders and sub-folders within it
http://stackoverflow.com/questions/4866 ... les-within
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: FTP Details
XTechVB
Codex wrote:
XTechVB wrote:
i'm making a ftp client but i cant find a way to delete a folder and all the other folders and sub-folders within it
http://stackoverflow.com/questions/4866 ... les-within
thats for the FtpWebRequest class! i'm using sockets
You can find me on Facebook or on Skype mihai_92b
6 posts Page 1 of 1
Return to “Tutorials”