bonjour

Pour tester la bonne connexion à un serveur FTP j'utilise ceci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
            FtpClient ftc = new FtpClient();
            String ListRepertoires = await ftc.ListDirectoryServeur(textBoxLogin.Text, textBoxPass.Text, textBoxHostName.Text, (int)numericUpDownFTP.Value, checkBoxSSLactif.Checked, FtpClient.ModePassif.Actif);
            if (ListRepertoires != "erreur!")
            {
                String reponse = "Les répertoires accessibles sont : \r\n" + ListRepertoires;
                MessageBox.Show(reponse);
            }
avec
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
public async Task<string> ListDirectoryServeur(String Login, String Pass, String HostName, int Port, bool SSL, bool ModePassif)
        {           
               try
               {
                var myUri = new Uri("ftp://" + HostName);
                var builder = new UriBuilder(myUri);
                builder.Port = Port;
 
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(builder.Uri.ToString()); 
                request.Method = WebRequestMethods.Ftp.ListDirectory;
                request.EnableSsl = (bool)SSL;
                request.UsePassive = (bool)ModePassif;
                request.KeepAlive = false;
 
                SecureString securePwd = new SecureString();
                securePwd = new NetworkCredential("", Pass).SecurePassword;
                request.Credentials = new NetworkCredential(Login, securePwd);
 
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(myCertificateValidation);
 
                string ReponseFTP = null;
 
                using (WebResponse response = await request.GetResponseAsync())
                {
                       using (Stream responseStream = response.GetResponseStream())
                       {
                           StreamReader reader = new StreamReader(responseStream);
 
                           ReponseFTP = reader.ReadToEnd();
                       }
                }
 
                return ReponseFTP;
 
                }
                catch (Exception Ex)
                {
                   MessageBox.Show(Ex.Message.ToString(), "Erreur !", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                   return "erreur!";
                }
 
 
        }
 
 
 
 
        /***************************************************************************************/
        //Fonction pour accepter le certificat SSL
        private bool myCertificateValidation(Object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors Errors)
        {
            return true;
        }
 
 
 
        public static class ModeSSL
        {
            public const bool Actif = true;
            public const bool Inactif = false;
        }
 
        public static class ModePassif
        {
            public const bool Actif = true;
            public const bool Inactif = false;
        }
Si je tape un chemin correctement, exemple : service.monsite.fr/RepertoireDeTravail cela fonctionne bien, ca me liste le contenu du répertoire RepertoireDeTravail
Si je tape le chemn de base (service.monsite.fr) ça me donne bien "RepertoireDeTravail"
mais si je tape le nom du répertoir avec une erreur de syntaxe (majuscule à la place d'une minuscule, lettre en plus ou en moins) par exemple service.monsite.fr/REPERTOIREDETRAVAIL

Alors je reçois "" en retour. en d'autres termes il y a erreur puisqu'il n'a pas pu se connecter au répertoire inexistant "REPERTOIREDETRAVAIL" mais il me retourne rien, comme s'il avait réussi à se connecter au répertoire mais qu'il était vide ; ce qui est faux et donc fort gênant...

Comment puis-je faire pour détecter que j'ai mal tapé le nom du répertoire ?
J'ai essayé de remplacer WebRequestMethods.Ftp.ListDirectory par WebRequestMethods.Ftp.PrintWorkingDirectory; pour pouvoir vérifier que je suis bien arrivé dans le répertoire que j'ai tapé et pas à la racine mais dans tous les cas ça me retourne "".

Question subsidiaire : pas moyens de comprendre comment récupérer tous les messages envoyés au serveur et retournés par le serveur ; tous ces messages que l'on voit défiler dans la console de tout bon client FTP, filezilla par exemple.

Merci