IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

lister les fichiers d'un serveur ftp


Sujet :

C++Builder

  1. #21
    Membre habitué Avatar de Mangacker
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    452
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2006
    Messages : 452
    Points : 181
    Points
    181
    Par défaut
    merci Crayon mais ton code ne marche pas tout a fait il me provoque une erreur lors du téléchargement
    un fichier est bien téléchargé depuis le serveur sur mon pc mais il apparait sous la forme
    -rw-rw-rw- 1 ftp ftp 18369 Mar 05 20
    ce qui fait qu'il est tout a fait innutilisable (il est vide)
    /**
    * Author: Tehem
    * Version: 2.0
    */
    Extension Twig pour Symfony 2.1 (Check Defined Constant)
    https://github.com/tehem/TwigConstantExtension

  2. #22
    Membre habitué Avatar de Mangacker
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    452
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2006
    Messages : 452
    Points : 181
    Points
    181
    Par défaut
    perso je pense que l'erreur pourrait etre réglée au moment de l'affichage des fichiers du serveur dans le TListBox
    procedure TForm1.ListBox1DblClick(Sender: TObject);
    var
    Entry: string;
    begin
    if Listbox1.Count > 0 then
    begin
    Entry := ListBox1.Items[ListBox1.ItemIndex];
    GetServerType(Entry);
    ChangeDir(Entry);
    DownLoad(Entry);
    end;
    end;
    en n'écrivant que le nom du fichier et son extension
    (de toute façon je n'utilise pas le reste)
    /**
    * Author: Tehem
    * Version: 2.0
    */
    Extension Twig pour Symfony 2.1 (Check Defined Constant)
    https://github.com/tehem/TwigConstantExtension

  3. #23
    Membre chevronné
    Avatar de Crayon
    Inscrit en
    Avril 2005
    Messages
    1 811
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 811
    Points : 2 189
    Points
    2 189
    Par défaut
    Salut, j'ai trouvé un lien vers un exemple BCB avec Indy 8: http://www.indyproject.org/sockets/D.../Indy8.EN.aspx

    Juste au cas où sa pourrais t'aider...
    • Plus un ordinateur possède de RAM, plus vite il peut générer un message d'erreur. - Dave Barry
    • Je n'ai pas peur des ordinateurs. J'ai peur qu'ils viennent à nous manquer. - Isaac Asimov
    • Le code source est comme une belle femme, plus on le regarde, plus on trouve des défauts. - Crayon

  4. #24
    Membre habitué Avatar de Mangacker
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    452
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2006
    Messages : 452
    Points : 181
    Points
    181
    Par défaut
    ok
    dis moi juste lequel des .zip as-tu téléchargé
    /**
    * Author: Tehem
    * Version: 2.0
    */
    Extension Twig pour Symfony 2.1 (Check Defined Constant)
    https://github.com/tehem/TwigConstantExtension

  5. #25
    Membre chevronné
    Avatar de Crayon
    Inscrit en
    Avril 2005
    Messages
    1 811
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 811
    Points : 2 189
    Points
    2 189
    Par défaut
    Celui qui dis Indy C++Builder Demos: http://www.nevrona.com/indy/download...os20010311.zip
    • Plus un ordinateur possède de RAM, plus vite il peut générer un message d'erreur. - Dave Barry
    • Je n'ai pas peur des ordinateurs. J'ai peur qu'ils viennent à nous manquer. - Isaac Asimov
    • Le code source est comme une belle femme, plus on le regarde, plus on trouve des défauts. - Crayon

  6. #26
    Membre actif Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Points : 206
    Points
    206
    Par défaut ca fontionne chez moi avec Bcb 6
    Voila, il te faut : 3 EditText , 2 bouton, 1 Memo

    ET 1 seul composant : NMFTP1

    le pti soft :

    1°) connexion a compte ftp
    2°) affiche l'arborescence
    3°) changement de repertoire
    4°) résultat dans le memo



    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
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    if (NMFTP1->Connected)
            NMFTP1->Disconnect() ;
    else
    {
            NMFTP1->Vendor = NMOS_AUTO;
            NMFTP1->Host = Edit3->Text ;
            NMFTP1->UserID = Edit2->Text ;
            NMFTP1->Password = Edit1->Text ;
            NMFTP1->Connect() ;
            NMFTP1->Nlist();
    }
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    void __fastcall TForm1::NMFTP1Connect(TObject *Sender)
    {
    AnsiString host = NMFTP1->Host ;
    Label1->Caption = "Connecter sous "+host ;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    void __fastcall TForm1::NMFTP1ListItem(AnsiString Listing)
    {
     Memo1->Clear();
     Memo1->Lines->Add(Listing);
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
      AnsiString TheDir;
      if (InputQuery("Changement de répertoire", "Quel répertoire?", TheDir))
        NMFTP1->ChangeDir(TheDir);
     
        NMFTP1->Nlist();
    }

  7. #27
    Responsable Magazine

    Avatar de pottiez
    Homme Profil pro
    Développeur C++
    Inscrit en
    Novembre 2005
    Messages
    7 152
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur C++
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2005
    Messages : 7 152
    Points : 22 087
    Points
    22 087
    Par défaut
    Citation Envoyé par Bily.sdi Voir le message
    ET 1 seul composant : NMFTP1
    Comme dit plus haut, le composant TNMFTP n'existe plus sous BCB2006
    Quand une réponse vous a été utile, pensez à utiliser le nouveau système de notation

    Lisez le magazine de developpez.com.
    Mes tutos : http://pottiez.developpez.com

    La FAQ BCB -> 642 Questions/Réponses, si vous voulez participer, contactez moi. Aide de BCB6 en français

    N'oubliez pas que l'aide existe et est affichée sous simple pression de la touche F1 , une touche c'est plus rapide que tout un message .

  8. #28
    Membre actif Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Points : 206
    Points
    206
    Par défaut
    Ben bizarre car je suis sous bcb 6.0 et je l'ai ?

    ah peut être que la version 2006 est une version plus récent ?

    la question est : bcb 6.0 est ce la version 2006 ?

    J'ai remarqué que j'ai un problème avec dans l'évènement NMFTP1Success

    NMFTP1->FTPDirectoryList->name est à NULL !!

    que manque t'il ou comment faire pour qu'il se remplisse automatiquement ?

    Merci

  9. #29
    Responsable Magazine

    Avatar de pottiez
    Homme Profil pro
    Développeur C++
    Inscrit en
    Novembre 2005
    Messages
    7 152
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur C++
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2005
    Messages : 7 152
    Points : 22 087
    Points
    22 087
    Par défaut
    La version 6.0 n'est pas la version 2006, la version 2006 est apparu en (2005-2006), la version 6.0 est apparu en 2003 (il me semble), en tout cas ce n'est pas du tout les même, il y as même une énorme différence
    Quand une réponse vous a été utile, pensez à utiliser le nouveau système de notation

    Lisez le magazine de developpez.com.
    Mes tutos : http://pottiez.developpez.com

    La FAQ BCB -> 642 Questions/Réponses, si vous voulez participer, contactez moi. Aide de BCB6 en français

    N'oubliez pas que l'aide existe et est affichée sous simple pression de la touche F1 , une touche c'est plus rapide que tout un message .

  10. #30
    Membre habitué Avatar de Mangacker
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    452
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2006
    Messages : 452
    Points : 181
    Points
    181
    Par défaut
    Citation Envoyé par pottiez Voir le message
    La version 6.0 n'est pas la version 2006, la version 2006 est apparu en (2005-2006), la version 6.0 est apparu en 2003 (il me semble), en tout cas ce n'est pas du tout les même, il y as même une énorme différence
    en effet de nombreux composants n'existent plus sous bcb2006 (qui est plus récent que la version 6)
    pourquoi??

    faudra demander aux développeurs...
    /**
    * Author: Tehem
    * Version: 2.0
    */
    Extension Twig pour Symfony 2.1 (Check Defined Constant)
    https://github.com/tehem/TwigConstantExtension

  11. #31
    Membre actif Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Points : 206
    Points
    206
    Par défaut
    alors la j'en sais rien !!

    Voila pour toi , tu télécharge la version pour Builder.

    il y a un exemple pour bcb 4 et bcb 5, sa compilera MAIS il te demandera
    le fichier indy50.lib pour l'exemple bcb5 ou indy40.lib pour l'exemple bcb4

    l'astuce : tu recherche dans ton pc le fichier indy.lib

    tu le colle dans le dossier ou se trouve l'exemple et tu le renomme par indy50.lib si tu veux utilise la version bcb5

    Le lien :
    http://www.indyproject.org/sockets/D.../Indy8.EN.aspx
    FTPDemo.rar

    petit problème : tu aura la liste des dossier et fichier mais avec le CHMOD

    tu peux retirer les CHMOD en mettant à false "option" la fonction
    IdFTP1->List(Form1->ListBox1->Items,"",option);
    Mais plus moyen d'ouvrir un dossier.

    à TOI de créer une liste que tu remplira avec la fonction : option = true;
    IdFTP1->List(Form1->ListBox1->Items,"",option);

    les 2 listes sont dans le même ordre !
    évènement sur l'un -> action sur l'autre

    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
     
     AnsiString Line;
      bool IsDirectory;
      int index;
      if (!IdFTP1->Connected())return;
      index=DirectoryListBox->ItemIndex;
      if (index==-1)return;
     
      Line = DirectoryListBox->Items->Strings[index];
      GetNameFromDirLine(Line, &IsDirectory);
     
     // en mettant IdFTP1->List(..,..,FALSE); &IsDirectory renvoi false !!!???
     // je ne sais pas pourquoi , ce qui implique l'impossibilité d'ouvrir un dossier
     // sans msg d'erreur. MAIS J'y travaille ;)
     
      if (IsDirectory)
      DownloadButton->Caption = "Change dir"; 
      else
      DownloadButton->Caption = "Download";
    SINON tout fonctionne ça marche

    Fichiers attachés Fichiers attachés

  12. #32
    Membre habitué Avatar de Mangacker
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    452
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2006
    Messages : 452
    Points : 181
    Points
    181
    Par défaut
    Citation Envoyé par Bily.sdi Voir le message
    l'astuce : tu recherche dans ton pc le fichier indy.lib

    tu le colle dans le dossier ou se trouve l'exemple et tu le renomme par indy50.lib si tu veux utilise la version bcb5
    je n'ai pas de fichier nommé indy.lib sur mon pc...
    /**
    * Author: Tehem
    * Version: 2.0
    */
    Extension Twig pour Symfony 2.1 (Check Defined Constant)
    https://github.com/tehem/TwigConstantExtension

  13. #33
    Membre chevronné
    Avatar de Crayon
    Inscrit en
    Avril 2005
    Messages
    1 811
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 811
    Points : 2 189
    Points
    2 189
    Par défaut
    C'est pourquoi Bily.sdi a mis un Fichier attaché à son message
    • Plus un ordinateur possède de RAM, plus vite il peut générer un message d'erreur. - Dave Barry
    • Je n'ai pas peur des ordinateurs. J'ai peur qu'ils viennent à nous manquer. - Isaac Asimov
    • Le code source est comme une belle femme, plus on le regarde, plus on trouve des défauts. - Crayon

  14. #34
    Membre habitué Avatar de Mangacker
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    452
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2006
    Messages : 452
    Points : 181
    Points
    181
    Par défaut
    c'est bien ce que j'avais compris mais il faut que je remplace le fichier de base par celui du lien

    et je n'ai pas le fichier de base
    /**
    * Author: Tehem
    * Version: 2.0
    */
    Extension Twig pour Symfony 2.1 (Check Defined Constant)
    https://github.com/tehem/TwigConstantExtension

  15. #35
    Membre actif Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Points : 206
    Points
    206
    Par défaut
    non ajoute le fichier dans le dossier ou se trouvera ton projet (ton .exe )

  16. #36
    Membre habitué Avatar de Mangacker
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    452
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2006
    Messages : 452
    Points : 181
    Points
    181
    Par défaut
    Citation Envoyé par Bily.sdi Voir le message
    non ajoute le fichier dans le dossier ou se trouvera ton projet (ton .exe )
    ok je teste quand j'ai un peu de temps
    /**
    * Author: Tehem
    * Version: 2.0
    */
    Extension Twig pour Symfony 2.1 (Check Defined Constant)
    https://github.com/tehem/TwigConstantExtension

  17. #37
    Membre habitué Avatar de Mangacker
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    452
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2006
    Messages : 452
    Points : 181
    Points
    181
    Par défaut
    désolé Bily.sdi mais je n'arrive à rien avec ton code
    /**
    * Author: Tehem
    * Version: 2.0
    */
    Extension Twig pour Symfony 2.1 (Check Defined Constant)
    https://github.com/tehem/TwigConstantExtension

  18. #38
    Membre actif Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Points : 206
    Points
    206
    Par défaut
    je recapitule :

    1°) prendre le fichier Indy50.lib que tu places dans le dossier de ton projet
    ( la ou il ya ton .exe )

    2°) le code .cpp

    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
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
     
     
    #include <vcl.h>
    #include <inifiles.hpp>
    #pragma hdrstop
     
    #include "MainForm.h"
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma link "IdBaseComponent"
    #pragma link "IdComponent"
    #pragma link "IdFTP"
    #pragma link "IdIntercept"
    #pragma link "IdLogBase"
    #pragma link "IdLogDebug"
    #pragma link "IdTCPClient"
    #pragma link "IdTCPConnection"
    #pragma link "IdAntiFreeze"
    #pragma link "IdAntiFreezeBase"
    #pragma resource "*.dfm"
    TfrmMain *frmMain;
    //---------------------------------------------------------------------------
    __fastcall TfrmMain::TfrmMain(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TfrmMain::ConnectButtonClick(TObject *Sender)
    {
     
      if (IdFTP1->Connected())
      {
      try
       {
        if (TransferrignData)
             IdFTP1->Abort();
        IdFTP1->Quit();
        IdFTP1->Disconnect();
        DirectoryListBox->Items->Clear();
        SetFunctionButtons(false);
        Panel3->Caption = "Current directory is: ";
     
        }
      catch(...)
      {
       ConnectButton->Caption = "Connect";
       ConnectButton->Enabled = true;
       ConnectButton->Default = true;
       return;
      }
       ConnectButton->Caption = "Connect";
       ConnectButton->Enabled = true;
       ConnectButton->Default = true;
     
      }
      else
       {  try
          {
          IdFTP1->User = UserIDEdit->Text;
          IdFTP1->Password = PasswordEdit->Text;
          IdFTP1->Host = FtpServerEdit->Text;
          IdFTP1->Connect(true);
          ConnectButton->Caption = "DisConnect";
          ConnectButton->Enabled = true;
          ConnectButton->Default = true;
          ChageDir("/");
          SetFunctionButtons(true);
          SaveHostInfo(FtpServerEdit->Text,"FTPHOST");//saving it here so that it is saved only after successful connect
          }
        catch(...)
          {if (IdFTP1->Connected())
             {
             ConnectButton->Enabled = true;
             ConnectButton->Caption = "Disconnect";
             ConnectButton->Default = false;
             }
             else
             {
              ConnectButton->Enabled = true;
              ConnectButton->Caption = "Connect";
             ConnectButton->Default = true;
             }
          }
        }
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmMain::SetFunctionButtons(bool Value)
    {
      int i;
      for (i = 0;i < CommandPanel->ControlCount; i++)
      {
       //if (CommandPanel->Controls[i]->Name != "AbortButton")
          //CommandPanel->Controls[i]->Enabled = Value;
      }
    }
     
     
    void __fastcall TfrmMain::ChageDir(AnsiString DirName)
    {
      try
      {
        SetFunctionButtons(false);
        IdFTP1->ChangeDir(DirName);
        IdFTP1->TransferType = ftASCII;
        Panel3->Caption = "Current directory is: " + IdFTP1->RetrieveCurrentDir() +
          "              Remote system is " + IdFTP1->SystemDesc;
        DirectoryListBox->Items->Clear();
     
        if(CHMOD->Checked==true)
         OPTION=true; else OPTION=false;
     
        IdFTP1->List(DirectoryListBox->Items,"",OPTION); // true pour les details CHMOD
        IdFTP1->List(Form1->ListBox1->Items,"",false);  // no CHMOD : resutal dans Form1->ListBox
     
        }
      __finally
        {
        SetFunctionButtons(true);
        }
    }
    void __fastcall TfrmMain::DirectoryListBoxDblClick(TObject *Sender)
    {
    AnsiString  Name;
    AnsiString Line;
    bool  IsDirectory;
    int index;
      if (!IdFTP1->Connected())return;
      index=DirectoryListBox->ItemIndex;
      if (index==-1)return;
      Line = DirectoryListBox->Items->Strings[index];
      Name = GetNameFromDirLine(Line, &IsDirectory);
     
      if (IsDirectory)
      {
        // Change directory
        SetFunctionButtons(false);
        ChageDir(Name);
        SetFunctionButtons(true);
      }
      else
      {
        try
         { SaveDialog1->FileName = Name;
          if (SaveDialog1->Execute())
          {
            SetFunctionButtons(false);
            IdFTP1->TransferType = ftBinary;
            BytesToTransfer = IdFTP1->Size(Name);
            IdFTP1->Get(Name, SaveDialog1->FileName, true);
          }
         }
        __finally
         { SetFunctionButtons(true);
         }
      }
     
     
    }
    //---------------------------------------------------------------------------
     
    AnsiString __fastcall TfrmMain::GetNameFromDirLine(AnsiString Line, bool *IsDirectory )
    {AnsiString result;
    int i;
    bool DosListing;
     
      *IsDirectory = (Line[1] == 'd');
      DosListing = false;
      for (i = 0;i <= 7;i++)
      {
        if ((i == 2) && (!*IsDirectory))
        { //IsDirectory =(Line.SubString(1,Line.Pos(' ') - 1) = "<DIR>");
          *IsDirectory = (bool)Line.AnsiPos("<DIR>");
     
          if (!*IsDirectory)
          DosListing = IsNumeric(Line[1]);
          else
          DosListing = true;
        }
        Line.Delete(1,  Line.Pos(' '));
        while (Line[1] == ' ')
         {
         Line.Delete(1, 1);
         };
        if ((DosListing)&&(i == 2))break;
      }
      result = Line;
     
    return result;
    }
    void __fastcall TfrmMain::UploadButtonClick(TObject *Sender)
    {
      if (IdFTP1->Connected())
      {
        if (UploadOpenDialog1->Execute())
        try
        { SetFunctionButtons(false);
          IdFTP1->TransferType = ftBinary;
          IdFTP1->Put(UploadOpenDialog1->FileName, ExtractFileName(UploadOpenDialog1->FileName),false);
          ChageDir(IdFTP1->RetrieveCurrentDir());
         }
        __finally
         { SetFunctionButtons(true);
         }
     
     }
     
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmMain::DeleteButtonClick(TObject *Sender)
    {
     
      AnsiString Name;
      AnsiString Line;
      bool IsDirectory;
    int index;
      if (!IdFTP1->Connected())return;
      index=DirectoryListBox->ItemIndex;
      if (index==-1)return;
     
      Line = DirectoryListBox->Items->Strings[index];
      Name = GetNameFromDirLine(Line, &IsDirectory);
      if (IsDirectory)
      {try
        {  SetFunctionButtons(false);
           IdFTP1->RemoveDir(Name);
           ChageDir(IdFTP1->RetrieveCurrentDir());
         }
         __finally
         {
         }
      }
      else
      {try
        {SetFunctionButtons(false);
         IdFTP1->Delete(Name);
         ChageDir(IdFTP1->RetrieveCurrentDir());
        }
      __finally
      {
      }
      }
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmMain::BackButtonClick(TObject *Sender)
    {
      if (!IdFTP1->Connected())return;
      try
      {
       ChageDir("..");
      }
      __finally
      {
      }
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmMain::AbortButtonClick(TObject *Sender)
    {
      AbortTransfer = true;        
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmMain::TraceCheckBoxClick(TObject *Sender)
    {
      IdLogDebug1->Active = TraceCheckBox->Checked;
      DebugListBox->Visible = TraceCheckBox->Checked;
      if (DebugListBox->Visible) Splitter1->Top = DebugListBox->Top + 5;
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmMain::SaveHostInfo(AnsiString Datatext,AnsiString header)
    {
     
        TIniFile * ServerIni;
        ServerIni = new TIniFile(ExtractFilePath(ParamStr(0)) + "FtpHost.ini");
     
        ServerIni->WriteString("Server", header, Datatext);
     
        delete   ServerIni;
     
    }
     
     
    AnsiString __fastcall TfrmMain::GetHostInfo(AnsiString header)
    {
        AnsiString ServerName;
        TIniFile * ServerIni;
        ServerIni = new TIniFile(ExtractFilePath(ParamStr(0)) + "FtpHost.ini");
     
        ServerName = ServerIni->ReadString("Server", header, header);
     
        delete   ServerIni;
    return ServerName;
    }
     
     
    void __fastcall TfrmMain::FormCreate(TObject *Sender)
    {
      SetFunctionButtons(false);
      IdLogDebug1->Active = true;
      FtpServerEdit->Text=GetHostInfo("FTPHOST");
     
      UserIDEdit->Text=GetHostInfo("LOGIN");
      PasswordEdit->Text=GetHostInfo("CODE");
     
      ProgressBar1->Parent = StatusBar1;
      ProgressBar1->Top = 2;
      ProgressBar1->Left = 1;
     
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TfrmMain::DirectoryListBoxClick(TObject *Sender)
    {
      AnsiString Line;
      bool IsDirectory;
      int index;
      if (!IdFTP1->Connected())return;
      index=DirectoryListBox->ItemIndex;
      if (index==-1)return;
     
      Line = DirectoryListBox->Items->Strings[index];
      GetNameFromDirLine(Line, &IsDirectory);
     
      if (IsDirectory)
      DownloadButton->Caption = "Change dir";
      else
      DownloadButton->Caption = "Download";
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TfrmMain::FormClose(TObject *Sender, TCloseAction &Action)
    {
    if (IdFTP1->Connected())
    IdFTP1->Disconnect();
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TfrmMain::IdLogDebug1LogItem(TComponent *ASender,
          AnsiString &AText)
    {
      DebugListBox->ItemIndex = DebugListBox->Items->Add(AText);
      Application->ProcessMessages();
     
    }
    //---------------------------------------------------------------------------
     
     
    void __fastcall TfrmMain::IdFTP1Disconnected(TObject *Sender)
    {
      StatusBar1->Panels->Items[1]->Text = "Disconnected.";
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TfrmMain::IdFTP1Status(TObject *axSender,
          const TIdStatus axStatus, const AnsiString asStatusText)
    {
      DebugListBox->ItemIndex = DebugListBox->Items->Add(asStatusText);
      StatusBar1->Panels->Items[1]->Text = asStatusText;
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TfrmMain::IdFTP1Work(TObject *Sender, TWorkMode AWorkMode,
          const int AWorkCount)
    {
    AnsiString  s;
    TDateTime  TotalTime;
    WORD H, M, Sec, MS;
    double DLTime;
     
      TotalTime =  Now() - STime;
      DecodeTime(TotalTime, H, M, Sec, MS);
      Sec = Sec + M * 60 + H * 3600;
      DLTime = Sec + MS / 1000;
      if (DLTime > 0)
        AverageSpeed = (AverageSpeed + (AWorkCount / 1024) / DLTime) / 2;
     
      s = FormatFloat("0.00 KB/s", AverageSpeed);
     
      switch (AWorkMode)
     { case  wmRead:
        { StatusBar1->Panels->Items[1]->Text = "Download speed " + s;
          break;
        }
        case wmWrite:
        {
         StatusBar1->Panels->Items[1]->Text = "Upload speed " + s;
        }
     };
     
      if (AbortTransfer)
       IdFTP1->Abort();
     
      ProgressBar1->Position = AWorkCount;
      AbortTransfer = false;
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TfrmMain::IdFTP1WorkBegin(TObject *Sender,
          TWorkMode AWorkMode, const int AWorkCountMax)
    {
      TransferrignData = true;
      AbortButton->Visible = true;
      AbortTransfer = false;
      STime = Now();
      if (AWorkCountMax > 0)
      ProgressBar1->Max = AWorkCountMax;
      else
      ProgressBar1->Max = BytesToTransfer;
      AverageSpeed = 0;
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TfrmMain::IdFTP1WorkEnd(TObject *Sender,
          TWorkMode AWorkMode)
    {
      AbortButton->Visible = false;
      StatusBar1->Panels->Items[1]->Text = "Transfer complete.";
      BytesToTransfer = 0;
      TransferrignData = false;
      ProgressBar1->Position = 0;
      AverageSpeed = 0;
     
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TfrmMain::UsePassiveClick(TObject *Sender)
    {
      IdFTP1->Passive = UsePassive->Checked;
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TfrmMain::Button1Click(TObject *Sender)
    {
    Form1->Show();
    }
    //---------------------------------------------------------------------------
    le code. h

    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
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
     
    //---------------------------------------------------------------------------
     
    #ifndef MainFormH
    #define MainFormH
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include "IdBaseComponent.hpp"
    #include "IdComponent.hpp"
    #include "IdFTP.hpp"
    #include "IdIntercept.hpp"
    #include "IdLogBase.hpp"
    #include "IdLogDebug.hpp"
    #include "IdTCPClient.hpp"
    #include "IdTCPConnection.hpp"
    #include <ComCtrls.hpp>
    #include <Dialogs.hpp>
    #include <ExtCtrls.hpp>
    #include "IdAntiFreeze.hpp"
    #include "IdAntiFreezeBase.hpp"
    #include <IdFinger.hpp>
    //---------------------------------------------------------------------------
    class TfrmMain : public TForm
    {
    __published:    // IDE-managed Components
            TSplitter *Splitter1;
            TListBox *DirectoryListBox;
            TListBox *DebugListBox;
            TPanel *Panel1;
            TLabel *Label1;
            TLabel *Label2;
            TLabel *Label3;
            TEdit *FtpServerEdit;
            TButton *ConnectButton;
            TPanel *Panel3;
            TCheckBox *TraceCheckBox;
            TEdit *UserIDEdit;
            TEdit *PasswordEdit;
            TPanel *CommandPanel;
            TButton *UploadButton;
            TButton *AbortButton;
            TButton *BackButton;
            TButton *DeleteButton;
            TButton *DownloadButton;
            TIdFTP *IdFTP1;
            TIdLogDebug *IdLogDebug1;
            TOpenDialog *UploadOpenDialog1;
            TSaveDialog *SaveDialog1;
            TProgressBar *ProgressBar1;
            TIdAntiFreeze *IdAntiFreeze1;
            TStatusBar *StatusBar1;
            TCheckBox *UsePassive;
            TIdFinger *IdFinger1;
            TCheckBox *CHMOD;
            TButton *Button1;
            void __fastcall ConnectButtonClick(TObject *Sender);
            void __fastcall DirectoryListBoxDblClick(TObject *Sender);
            void __fastcall UploadButtonClick(TObject *Sender);
            void __fastcall DeleteButtonClick(TObject *Sender);
            void __fastcall BackButtonClick(TObject *Sender);
            void __fastcall AbortButtonClick(TObject *Sender);
            void __fastcall TraceCheckBoxClick(TObject *Sender);
            void __fastcall FormCreate(TObject *Sender);
            void __fastcall DirectoryListBoxClick(TObject *Sender);
            void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
            void __fastcall IdLogDebug1LogItem(TComponent *ASender,
              AnsiString &AText);
            void __fastcall IdFTP1Disconnected(TObject *Sender);
            void __fastcall IdFTP1Status(TObject *axSender,
              const TIdStatus axStatus, const AnsiString asStatusText);
            void __fastcall IdFTP1Work(TObject *Sender, TWorkMode AWorkMode,
              const int AWorkCount);
            void __fastcall IdFTP1WorkBegin(TObject *Sender,
              TWorkMode AWorkMode, const int AWorkCountMax);
            void __fastcall IdFTP1WorkEnd(TObject *Sender,
              TWorkMode AWorkMode);
            void __fastcall UsePassiveClick(TObject *Sender);
            void __fastcall Button1Click(TObject *Sender);
    private:  bool AbortTransfer;
              bool TransferrignData;
              long BytesToTransfer ;
              TDateTime STime;
              double AverageSpeed;
              bool OPTION;
        // User declarations
    public:        // User declarations
            __fastcall TfrmMain(TComponent* Owner);
            void __fastcall SetFunctionButtons(bool Value);
            void __fastcall ChageDir(AnsiString DirName);
            AnsiString __fastcall GetNameFromDirLine(AnsiString Line, bool *IsDirectory );
            void __fastcall SaveHostInfo(AnsiString Datatext,AnsiString header);
            AnsiString __fastcall GetHostInfo(AnsiString header);
     
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TfrmMain *frmMain;
    //---------------------------------------------------------------------------
    #endif
    y a des ligne que tu peuvent être amélioré , comme par exemple tester
    si la ligne sélectionnée est un fichier ou dossier !

    voila , je pense que cela devrais aller

    je crée un accès opensource pour vous tous, j'y placerai des exemples de code

    sinon le code se trouve ici : http://www.createsoft.be/opensource/

    FTP-builder-Indy.rar & ftp-builder-NMFTP.rar


    @+
    Images attachées Images attachées  

  19. #39
    Membre habitué Avatar de Mangacker
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    452
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2006
    Messages : 452
    Points : 181
    Points
    181
    Par défaut
    ok je le teste dès que je peux

    encore merci pour tout le temps que vous prenez à m'expliquer tout ça
    /**
    * Author: Tehem
    * Version: 2.0
    */
    Extension Twig pour Symfony 2.1 (Check Defined Constant)
    https://github.com/tehem/TwigConstantExtension

  20. #40
    Membre habitué Avatar de Mangacker
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    452
    Détails du profil
    Informations personnelles :
    Âge : 32
    Localisation : Suisse

    Informations forums :
    Inscription : Décembre 2006
    Messages : 452
    Points : 181
    Points
    181
    Par défaut
    j'ai quand meme une question:
    à quoi correspond Panel pour toi??
    /**
    * Author: Tehem
    * Version: 2.0
    */
    Extension Twig pour Symfony 2.1 (Check Defined Constant)
    https://github.com/tehem/TwigConstantExtension

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 3 PremièrePremière 123 DernièreDernière

Discussions similaires

  1. [Free Pascal] Problème pour lister les fichiers d'un serveur distant
    Par mm_71 dans le forum Free Pascal
    Réponses: 6
    Dernier message: 26/06/2013, 09h52
  2. afficher les fichiers stockés sur serveur ftp
    Par stagolee dans le forum Hébergement
    Réponses: 2
    Dernier message: 27/11/2007, 18h41
  3. Réponses: 2
    Dernier message: 13/10/2007, 14h30
  4. Lister les fichiers d'un répertoire FTP
    Par voulton dans le forum Web
    Réponses: 2
    Dernier message: 05/08/2007, 19h06
  5. Réponses: 1
    Dernier message: 28/06/2007, 11h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo