Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I want to build a Windows Mobile application which connects to a (remote) FTP-server and download a certain FTP-directory with all subdirectories.

I've found OpenNetCF and was already able to get a directory listing on one level, but if I go one level deeper (recursive), the application crashes on 'FTP cannot connect to remote server'.

My code:
VB
Private m_ftp As FTP
    Private _LocalSubDirectory As String = ""
    Private _RemoteDirectories As New ArrayList
	
    Private Sub ftpDownload(ByVal ftpDirectory As String)
        m_ftp.RemoteDirectory = ftpDirectory

        Dim ftpDirectoryName As String = ""
        Dim ftpFiles As FTPFiles = m_ftp.EnumFiles
        For Each file As FTPFile In ftpFiles
            If file.Type = FTPFileType.Directory Then
                ftpDirectoryName = file.Name
                If Not (ftpDirectoryName.EndsWith(" .") Or ftpDirectoryName.EndsWith(" ..")) Then
                    Dim posL As Integer = ftpDirectoryName.IndexOf(" ")
                    ftpDirectoryName = ftpDirectoryName.Substring(posL + 1, ftpDirectoryName.Length - posL - 1)
                    _RemoteDirectories.Add(ftpDirectoryName)

                    If ftpDirectoryHasFolders(ftpDirectoryName) Then
                        _LocalSubDirectory += ftpDirectoryName + "\"
                        ftpDownload(ftpDirectoryName)
                    End If
                End If
            End If
        Next

        m_ftp.ChangeDirectory("..")
    End Sub
	
    Private Function ftpDirectoryHasFolders(ByVal ftpDirectory As String) As Boolean
        Dim result As Boolean = False

        m_ftp.RemoteDirectory = ftpDirectory

        Dim ftpFiles As FTPFiles = m_ftp.EnumFiles
        For Each file As FTPFile In ftpFiles
            If file.Type = FTPFileType.Directory Then
                Dim ftpDirectoryName As String = file.Name
                If Not (ftpDirectoryName.EndsWith(" .") Or ftpDirectoryName.EndsWith(" ..")) Then
                    result = True
                End If
            End If
        Next

        m_ftp.ChangeDirectory("..")

        Return result
    End Function

- Windows Mobile 6
- Compact Framework 3.5
- VS2008

Any ideas ?
Posted
v2
Comments
Luk Vandevyvere 23-Nov-12 6:11am    
Really, no one ?
Member 14037214 13-Dec-19 2:38am    
did you solve this yet?

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