none
Tester l’existence d'un dossier sur FTP RRS feed

Réponses

  • Bonjour,

    voici un exemple pour tester si le dossier existe :

    Public Function FtpFileExist(Url_Filename As String, Login As String, Password As String) As Boolean
     
            Dim req As FtpWebRequest = CType(FtpWebRequest.Create(Url_Filename), FtpWebRequest)
            Dim FileName As String = Url_Filename.Substring(Url_Filename.LastIndexOf("/") + 1)
            req.Method = WebRequestMethods.Ftp.DownloadFile
            req.Credentials = New System.Net.NetworkCredential(Login, Password)
            Dim resp As FtpWebResponse = Nothing
            Try
                resp = CType(req.GetResponse, FtpWebResponse)
            Catch ex As Exception
                Return False
            End Try
     
            If resp.StatusDescription.Contains(FileName) Then
                FtpFileExist = True
            Else
                FtpFileExist = False
            End If
     
            resp.Close()
            resp.Dispose()
            resp = Nothing
            req = Nothing
        End Function

    cordialement,

    lundi 25 novembre 2019 11:25

Toutes les réponses

  • Je fais comme cela mais j'ignore s'il y a mieux :

            Dim Demande As FtpWebRequest, Reponse As String = "", Liste As New List(Of String), Trouve As Boolean = False
    
            'Teste l'existance du dossier ID
            Try
                Dim request As FtpWebRequest = CType(WebRequest.Create("ftp://00.000.0.00/httpdocs/cloud"), FtpWebRequest)
                request.Method = WebRequestMethods.Ftp.ListDirectory
                request.Credentials = New NetworkCredential("", "")
                Dim response As FtpWebResponse = CType(request.GetResponse(), FtpWebResponse)
                Dim responseStream As Stream = response.GetResponseStream()
                Dim reader As StreamReader = New StreamReader(responseStream)
                Dim names As String = reader.ReadToEnd()
                reader.Close()
                response.Close()
                Liste = names.Split(New String() {vbCrLf}, StringSplitOptions.RemoveEmptyEntries).ToList()
            Catch __unusedException1__ As Exception
                Throw
            End Try
    
            For I = 0 To Liste.Count - 1
                If Liste(I) = "1" Then Trouve = True
            Next
    


    lundi 25 novembre 2019 05:42
  • Bonjour,

    voici un exemple pour tester si le dossier existe :

    Public Function FtpFileExist(Url_Filename As String, Login As String, Password As String) As Boolean
     
            Dim req As FtpWebRequest = CType(FtpWebRequest.Create(Url_Filename), FtpWebRequest)
            Dim FileName As String = Url_Filename.Substring(Url_Filename.LastIndexOf("/") + 1)
            req.Method = WebRequestMethods.Ftp.DownloadFile
            req.Credentials = New System.Net.NetworkCredential(Login, Password)
            Dim resp As FtpWebResponse = Nothing
            Try
                resp = CType(req.GetResponse, FtpWebResponse)
            Catch ex As Exception
                Return False
            End Try
     
            If resp.StatusDescription.Contains(FileName) Then
                FtpFileExist = True
            Else
                FtpFileExist = False
            End If
     
            resp.Close()
            resp.Dispose()
            resp = Nothing
            req = Nothing
        End Function

    cordialement,

    lundi 25 novembre 2019 11:25
  • Merci
    samedi 14 décembre 2019 11:32