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

Composants VCL Delphi Discussion :

Conseil pour Transfert FTP avec Delphi Studio 2006 Express


Sujet :

Composants VCL Delphi

  1. #1
    Membre actif
    Inscrit en
    Février 2009
    Messages
    616
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 616
    Points : 249
    Points
    249
    Par défaut Conseil pour Transfert FTP avec Delphi Studio 2006 Express
    Bonjour, je possède une vielle version de Delphi studio 2006 Express gratuite, celle-ci semble etre bridée pour ce qui est d'installer de nouveaux composants...

    J'ai besoin de réaliser un transfert ftp d'un fichier local via un serveur distant,
    le pb qui se pose, c'est que cette version ne possède pas les composants Indy et pas moyen de les installer,

    Je cherche donc une solution pour contourner ce pb.


    Auriez-vous un conseil à ce sujet ?


    Merci.

  2. #2
    Membre éprouvé

    Profil pro
    Inscrit en
    Mai 2003
    Messages
    582
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Mai 2003
    Messages : 582
    Points : 915
    Points
    915
    Par défaut
    Dans le defit des serpents, mon
    système de Hi-Score sur internet était basé
    sur un échange de fichier via ftp.

    voici l'unité que j'avais pondu à ce moment...
    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
     
    //==============================================================================
    //=== FTWininet
    //=== Basic FTP functions via wininet.dll
    //=== Compatible with Win95 and Over!
    //=== Eric Boisvert
    //==============================================================================
     
    Unit FTPWininet;
     
    Interface
     
    Uses windows, sysutils, classes, wininet;
     
     
    {==============================================================================}
    {                                }Const {                                      }
    {==============================================================================}
      ApplicationName = 'SnakeEatFrog.exe';
      FTPSite = 'eboisvert.no-ip.org';
      FTPUser = 'Snake';
      FTPPWD = '!2SnakeHiScore*&';
     
     
    {========================== Public Functions ==================================}
    Function SendFTPFile(LocalFilePath: String): Boolean;
    Function FTPFileExist(RemoteFileName: String): Boolean;
    Function GetFTPFile(RemoteFilePath: String; LocalFileName: String): Boolean;
     
     
    {==============================================================================}
    {                            }Implementation {                                 }
    {==============================================================================}
     
     
    //==============================================================================
    //== Send a file at root directory of the FTP Server
    Function SendFTPFile(LocalFilePath: String): Boolean;
    Var
      hOpen: HINTERNET;
      hConnection: HINTERNET;
      remoteFileName: String;
    Begin
      result := false;
     
      //open an internet connection
      hOpen := InternetOpen(ApplicationName, INTERNET_OPEN_TYPE_PRECONFIG, Nil, Nil, 0);
      //connect to the FTP server
      hConnection := InternetConnect(hOpen, FTPSite,
        INTERNET_DEFAULT_FTP_PORT,
        FTPUser, FTPPWD, INTERNET_SERVICE_FTP,
        0, 0);
      RemoteFileName := ExtractFileName(LocalFilePath);
      Try
        //== Upload a file ==
        If FtpPutFile(hConnection, PChar(LocalFilePath), PChar(RemoteFileName), FTP_TRANSFER_TYPE_BINARY, 0) = TRUE Then
          result := TRUE;
      Finally
        //close the FTP connection
        InternetCloseHandle(hConnection);
        //close the internet connection
        InternetCloseHandle(hOpen);
      End;
    End;
     
     
    //==============================================================================
    //== Get a file from the root directory of the FTP Server
    Function GetFTPFile(RemoteFilePath: String; LocalFileName: String): Boolean;
    Var
      hOpen: HINTERNET;
      hConnection: HINTERNET;
    Begin
      result := FALSE;
      //== open an internet connection ==
      hOpen := InternetOpen(ApplicationName, INTERNET_OPEN_TYPE_PRECONFIG, Nil, Nil, 0);
      //== connect to the FTP server ==
      hConnection := InternetConnect(hOpen, FTPSite,
        INTERNET_DEFAULT_FTP_PORT,
        FTPUser, FTPPWD, INTERNET_SERVICE_FTP,
        0, 0);
      Try
        If FtpGetFile(hConnection, pChar(RemoteFilePath),
          PChar(LocalFileName), False, 0,
          FTP_TRANSFER_TYPE_BINARY, 0) Then result := TRUE;
      Finally
        //close the FTP connection
        InternetCloseHandle(hConnection);
        //close the internet connection
        InternetCloseHandle(hOpen);
      End;
     
    End;
     
     
    //==============================================================================
    //== Helper fonction to retrive all remote file name on the current FTP
    //== connection.
    //== NOTES: This fonction create a TStringList...The caller MUST free it!
    Function EnumFiles(hConnection: HINTERNET): TStringList;
    Var
      pData: WIN32_FIND_DATA;
      hFind: HINTERNET;
    Begin
      result := TStringList.Create();
      //== find the first file ==
      hFind := FtpFindFirstFile(hConnection, '*.*', pData, 0, 0);
      If hFind = Nil Then Exit;
      Try
        //== store the filename in the StringList ==
        result.Add(trim(pData.cFileName));
        //== Try to find an other file ==
        While (InternetFindNextFile(hFind, @pData) = TRUE) Do
        Begin
          //== store the filename in the StringList ==
          result.Add(trim(pData.cFileName));
        End;
      Finally
        //== close the internet search handle ==
        InternetCloseHandle(hFind);
      End;
    End;
     
     
    //==============================================================================
    //== Determine if a file exist on FTP Root directory
    Function FTPFileExist(RemoteFileName: String): Boolean;
    Var
      hOpen: HINTERNET;
      hConnection: HINTERNET;
      FileList: TStringList;
      FindIndex: integer;
    Begin
      result := FALSE;
      //== open an internet connection ==
      hOpen := InternetOpen(ApplicationName, INTERNET_OPEN_TYPE_PRECONFIG, Nil, Nil, 0);
      //== connect to the FTP server ==
      hConnection := InternetConnect(hOpen, FTPSite,
        INTERNET_DEFAULT_FTP_PORT,
        FTPUser, FTPPWD, INTERNET_SERVICE_FTP,
        0, 0);
      //== Retrive all file in the remote server ==
      FileList := EnumFiles(hConnection);
      Try
        FileList.Sort;
        //== check if our file is in the list ==
        If FileList.Find(RemoteFileName, FindIndex) Then
          result := TRUE;
      Finally
        //== Cleanup ==
        FileList.Clear;
        FileList.Free;
        //close the FTP connection
        InternetCloseHandle(hConnection);
        //close the internet connection
        InternetCloseHandle(hOpen);
      End;
    End;
     
     
    End.
    Tu peux modifier cette unité pour répondre à tes besoins.
    Bon code!
    Comment dupliquer un disque...ça vous intéresse?
    Tutoriel et code source delphi ici

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Transfert FTP avec un PDA en Visual studio 2008
    Par Didier L dans le forum VB.NET
    Réponses: 2
    Dernier message: 06/11/2012, 13h50
  2. Réponses: 7
    Dernier message: 06/12/2005, 16h04
  3. transfert ftp avec le composant
    Par sillycoder dans le forum Composants VCL
    Réponses: 3
    Dernier message: 19/05/2005, 09h35
  4. Réponses: 2
    Dernier message: 20/03/2002, 23h01

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