Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Check for no FTP files
Message
De
08/12/2014 08:10:27
 
 
À
08/12/2014 04:24:07
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01611973
Message ID:
01611978
Vues:
28
>any thoughts on the best way to check for no files in an ftp folder ?
>
>I've got this
>
>
> FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpaddress);
> //List all the files in the directory
> request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
>
>
>I think I can check for file = 0 but I wondered if there as anything else.
>
>Thanks
>
>Nick
>
>
>Update the FTP site returns "total 0"

That's interesting. I never thought to use that shortcut. I always used a general approach and checking the collection after. Here is a part of the code I use:
                    ' FTP setup
                    loFtpWebRequest = System.Net.FtpWebRequest.Create(New Uri(lcURI))
                    loFtpWebRequest.Credentials = New System.Net.NetworkCredential(cUsername, cPassword)
                    loFtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails
                    loFtpWebRequest.KeepAlive = False

                    ' If we use FTP/SSL  (AUTH SSL)
                    If nNoFTPProtocol = 2 Then
                        loFtpWebRequest.EnableSsl = True
                    End If

                    Using loFtpWebResponse As System.Net.FtpWebResponse = loFtpWebRequest.GetResponse()

                        Using loStream As System.IO.Stream = loFtpWebResponse.GetResponseStream()

                            Using loStreamReader As New StreamReader(loStream)

                                ' Load the files into the string builder
                                loStringBuilder.LoadString(loStreamReader.ReadToEnd())

                            End Using

                        End Using

                    End Using

                    ' Initialization
                    cDirectoryContentFromFTP = loStringBuilder.oStringBuilder.ToString

                    ' For each file
                    For lnCounter2 = 1 To loStringBuilder.nLine
So, basically, it is the same start as you. Then, I stream and put each line into a collection.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform