begin process at 2010 02 09 23:28:20
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

API

 > FTP ( DOWNLOAD,UPLOAD,SUPPRIMME,RENOMME,DOSSIER... )

FTP ( DOWNLOAD,UPLOAD,SUPPRIMME,RENOMME,DOSSIER... )


 Information sur la source

Note :
8,33 / 10 - par 6 personnes
8,33 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :API Niveau :Débutant Date de création :15/07/2002 Date de mise à jour :02/10/2003 20:25:47 Vu / téléchargé :14 629 / 1 358

Auteur : SHIVA

Ecrire un message privé
Site perso
Commentaire sur cette source (23)
Ajouter un commentaire et/ou une note

 Description

Ce code est tiré de API-Guide 3.7 (www.allapi.net)

DOWNLOAD,UPLOAD,SUPPRIMME,RENOMM E,DOSSIER...

Source

  • Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
  • Const FTP_TRANSFER_TYPE_ASCII = &H1
  • Const FTP_TRANSFER_TYPE_BINARY = &H2
  • Const INTERNET_DEFAULT_FTP_PORT = 21 ' default for FTP servers
  • Const INTERNET_SERVICE_FTP = 1
  • Const INTERNET_FLAG_PASSIVE = &H8000000 ' used for FTP connections
  • Const INTERNET_OPEN_TYPE_PRECONFIG = 0 ' use registry configuration
  • Const INTERNET_OPEN_TYPE_DIRECT = 1 ' direct to net
  • Const INTERNET_OPEN_TYPE_PROXY = 3 ' via named proxy
  • Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4 ' prevent using java/script/INS
  • Const MAX_PATH = 260
  • Private Type FILETIME
  • dwLowDateTime As Long
  • dwHighDateTime As Long
  • End Type
  • Private Type WIN32_FIND_DATA
  • dwFileAttributes As Long
  • ftCreationTime As FILETIME
  • ftLastAccessTime As FILETIME
  • ftLastWriteTime As FILETIME
  • nFileSizeHigh As Long
  • nFileSizeLow As Long
  • dwReserved0 As Long
  • dwReserved1 As Long
  • cFileName As String * MAX_PATH
  • cAlternate As String * 14
  • End Type
  • Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
  • Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
  • Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
  • Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
  • Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
  • Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
  • Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
  • Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
  • Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
  • Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Long, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef dwContext As Long) As Boolean
  • Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
  • Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean
  • Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
  • Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
  • Const PassiveConnection As Boolean = True
  • Private Sub Form_Load()
  • 'KPD-Team 2000
  • 'URL: http://www.allapi.net
  • 'E-Mail: KPDTeam@allapi.net
  • Dim hConnection As Long, hOpen As Long, sOrgPath As String
  • 'open an internet connection
  • hOpen = InternetOpen("API-Guide sample program", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
  • 'connect to the FTP server
  • hConnection = InternetConnect(hOpen, "your ftp server", INTERNET_DEFAULT_FTP_PORT, "your login", "your password", INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
  • 'create a buffer to store the original directory
  • sOrgPath = String(MAX_PATH, 0)
  • 'get the directory
  • FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath)
  • 'create a new directory 'testing'
  • FtpCreateDirectory hConnection, "testing"
  • 'set the current directory to 'root/testing'
  • FtpSetCurrentDirectory hConnection, "testing"
  • 'upload the file 'test.htm'
  • FtpPutFile hConnection, "C:\test.htm", "test.htm", FTP_TRANSFER_TYPE_UNKNOWN, 0
  • 'rename 'test.htm' to 'apiguide.htm'
  • FtpRenameFile hConnection, "test.htm", "apiguide.htm"
  • 'enumerate the file list from the current directory ('root/testing')
  • EnumFiles hConnection
  • 'retrieve the file from the FTP server
  • FtpGetFile hConnection, "apiguide.htm", "c:\apiguide.htm", False, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0
  • 'delete the file from the FTP server
  • FtpDeleteFile hConnection, "apiguide.htm"
  • 'set the current directory back to the root
  • FtpSetCurrentDirectory hConnection, sOrgPath
  • 'remove the direcrtory 'testing'
  • FtpRemoveDirectory hConnection, "testing"
  • 'close the FTP connection
  • InternetCloseHandle hConnection
  • 'close the internet connection
  • InternetCloseHandle hOpen
  • End Sub
  • Public Sub EnumFiles(hConnection As Long)
  • Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
  • 'set the graphics mode to persistent
  • Me.AutoRedraw = True
  • 'create a buffer
  • pData.cFileName = String(MAX_PATH, 0)
  • 'find the first file
  • hFind = FtpFindFirstFile(hConnection, "*.*", pData, 0, 0)
  • 'if there's no file, then exit sub
  • If hFind = 0 Then Exit Sub
  • 'show the filename
  • Me.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
  • Do
  • 'create a buffer
  • pData.cFileName = String(MAX_PATH, 0)
  • 'find the next file
  • lRet = InternetFindNextFile(hFind, pData)
  • 'if there's no next file, exit do
  • If lRet = 0 Then Exit Do
  • 'show the filename
  • Me.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
  • Loop
  • 'close the search handle
  • InternetCloseHandle hFind
  • End Sub
  • Sub ShowError()
  • Dim lErr As Long, sErr As String, lenBuf As Long
  • 'get the required buffer size
  • InternetGetLastResponseInfo lErr, sErr, lenBuf
  • 'create a buffer
  • sErr = String(lenBuf, 0)
  • 'retrieve the last respons info
  • InternetGetLastResponseInfo lErr, sErr, lenBuf
  • 'show the last response info
  • MsgBox "Error " + CStr(lErr) + ": " + sErr, vbOKOnly + vbCritical
  • End Sub
Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const FTP_TRANSFER_TYPE_BINARY = &H2
Const INTERNET_DEFAULT_FTP_PORT = 21               ' default for FTP servers
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000            ' used for FTP connections
Const INTERNET_OPEN_TYPE_PRECONFIG = 0                    ' use registry configuration
Const INTERNET_OPEN_TYPE_DIRECT = 1                        ' direct to net
Const INTERNET_OPEN_TYPE_PROXY = 3                         ' via named proxy
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4   ' prevent using java/script/INS
Const MAX_PATH = 260
Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
End Type
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Long, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef dwContext As Long) As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Const PassiveConnection As Boolean = True
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net
    'E-Mail: KPDTeam@allapi.net
    Dim hConnection As Long, hOpen As Long, sOrgPath  As String
    'open an internet connection
    hOpen = InternetOpen("API-Guide sample program", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    'connect to the FTP server
    hConnection = InternetConnect(hOpen, "your ftp server", INTERNET_DEFAULT_FTP_PORT, "your login", "your password", INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
    'create a buffer to store the original directory
    sOrgPath = String(MAX_PATH, 0)
    'get the directory
    FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath)
    'create a new directory 'testing'
    FtpCreateDirectory hConnection, "testing"
    'set the current directory to 'root/testing'
    FtpSetCurrentDirectory hConnection, "testing"
    'upload the file 'test.htm'
    FtpPutFile hConnection, "C:\test.htm", "test.htm", FTP_TRANSFER_TYPE_UNKNOWN, 0
    'rename 'test.htm' to 'apiguide.htm'
    FtpRenameFile hConnection, "test.htm", "apiguide.htm"
    'enumerate the file list from the current directory ('root/testing')
    EnumFiles hConnection
    'retrieve the file from the FTP server
    FtpGetFile hConnection, "apiguide.htm", "c:\apiguide.htm", False, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0
    'delete the file from the FTP server
    FtpDeleteFile hConnection, "apiguide.htm"
    'set the current directory back to the root
    FtpSetCurrentDirectory hConnection, sOrgPath
    'remove the direcrtory 'testing'
    FtpRemoveDirectory hConnection, "testing"
    'close the FTP connection
    InternetCloseHandle hConnection
    'close the internet connection
    InternetCloseHandle hOpen
End Sub
Public Sub EnumFiles(hConnection As Long)
    Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
    'set the graphics mode to persistent
    Me.AutoRedraw = True
    'create a buffer
    pData.cFileName = String(MAX_PATH, 0)
    'find the first file
    hFind = FtpFindFirstFile(hConnection, "*.*", pData, 0, 0)
    'if there's no file, then exit sub
    If hFind = 0 Then Exit Sub
    'show the filename
    Me.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    Do
        'create a buffer
        pData.cFileName = String(MAX_PATH, 0)
        'find the next file
        lRet = InternetFindNextFile(hFind, pData)
        'if there's no next file, exit do
        If lRet = 0 Then Exit Do
        'show the filename
        Me.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    Loop
    'close the search handle
    InternetCloseHandle hFind
End Sub
Sub ShowError()
    Dim lErr As Long, sErr As String, lenBuf As Long
    'get the required buffer size
    InternetGetLastResponseInfo lErr, sErr, lenBuf
    'create a buffer
    sErr = String(lenBuf, 0)
    'retrieve the last respons info
    InternetGetLastResponseInfo lErr, sErr, lenBuf
    'show the last response info
    MsgBox "Error " + CStr(lErr) + ": " + sErr, vbOKOnly + vbCritical
End Sub
 

 Conclusion

Merci

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip FTP ( DOWNLOAD,UPLOAD,SUPPRIMME,RENOMME,DOSSIER... ) V2
Source avec Zip WINSOCK MULTICONNECTION SUR UN MEME PORT
ACTIVE TELNET
OUVRIR UN FICHIER A PARTIR DE VISUAL BASIC

 Sources de la même categorie

Source avec Zip Source avec une capture Source .NET (Dotnet) FAIRE LA DIFFÉRENCE ENTRE UNE ADRESSE EMAIL QUI EXISTE D'UNE... par lesinfosdugeek
ENVOYER UN MESSAGE SUR SON COMPTE TWITTER par lesinfosdugeek
Source avec Zip Source avec une capture TROUVER LES CLÉS DE REGISTRE QUI CHANGENT par Flocreate
Source avec Zip IP_PUBLIQUE_INTERNETGETCONNECTEDSTATE par marco62118
Source avec Zip TOUTES LES RÉSOLUTIONS D'ÉCRAN ET TAILLE MAXI DE LA FORM AUD... par marco62118

Commentaires et avis

Commentaire de Jackboy le 15/07/2002 00:43:25

un tit zip !!!

Commentaire de SHIVA le 15/07/2002 00:55:05

le zip est pret

Commentaire de Alain Proviste le 15/07/2002 22:27:51 administrateur CS

Mieux que cuteFtp ;)

Commentaire de SHIVA le 15/07/2002 23:09:29

Merci beaucoup

Commentaire de KIRU le 15/07/2002 23:46:08

Elle  est trop bien ta source

Felicitation

Commentaire de TheSaib le 16/07/2002 17:44:26 administrateur CS

le probleme c'est que tu met un Zip et tu montre aucun exemple , donc ton zip est d'aucune utilité , tout comme le code dans cet état là !

Commentaire de SHIVA le 16/07/2002 18:45:36

tu n' as qu'à taper le serveur ftp,le motdepasse , le compte.
et  crée un fichier c: est.htm
et tu verras.

Commentaire de FleX le 05/09/2002 12:39:17

SUPER UTILE !!!!

mais moi je'm galere a le porter en VB.net c trop la misere

surtout le type kil veut plus don -> structure
et FILETIME il ne connait po :(

quelqu'un sait comment faire ?

Commentaire de mclic le 11/09/2002 17:06:50

salut comment faire pour envoyer un fichier "TXT" sur un "FTP" puis crée un dossier pour mettre le fichier "TXT" exemple: http://www.multimania.com/"lelogin"/allo/"FichierTXT"

et de recevoir les donnés du fichier "TXT" dans une textbox d'un prog vb.

merci de me repondre.
- mclic -

Commentaire de SHIVA le 14/09/2002 12:12:20

pour mclic: tout est dans la source

Commentaire de Jin le 13/12/2002 13:20:08

J'ai un poil de mal à lire le code à la volée.

Mais d'après le "Private Type WIN32_FIND_DATA", il semble possible de se connecter à un FTP puis de parcourir les dossiers, récupérer les noms, les tailles, les dates de modifications etc... de ces fichiers.

J'ai un hébergeur qui ne fait pas l'ASP. Donc impossible de récupérer toutes ces infos de fichiers, mais il semblerait que ce code soit une alternative...

Isn't it ?

Commentaire de Jin le 12/01/2003 00:06:53

Yes it is, je l'ai exploité et j'ai récupérer ce que je voulais. Source utile et exploitable. Merci

Commentaire de FredJust le 20/02/2003 00:12:53

un simple copier coller de All Api ?!
CF
'KPD-Team 2000
'URL: http://www.allapi.net
'E-Mail: KPDTeam@allapi.net

Commentaire de joina le 07/05/2003 11:48:30

moi ça me lance juste une fenetre vide

Commentaire de SHIVA le 07/05/2003 13:42:10

joina: tu dois entrer ton server ftp, ton username et ton password puis crée un fichier test.htm sur ton c: , normalement un fichier apiguide doit apparaitre dans ton c:
ce qui se passe :
le prog crée un dossier "testing" dans ton ftp
puis rentre dans testing
puis upload le fichier "test.htm"vers le ftp sous le nom de "test.htm
puis renomme test.htm en apiguide.htm
puis download le fichier apiguide.htm vers ton c:
puis supprime apiguide.htm de ton ftp
puis supprime le dossier testing dans ton ftp

Commentaire de LuTo le 29/05/2003 22:44:08

Merci pour cette source simple, efficace et hyper reutilisable sur le sujet. Tout est la, c'est que du bonheur. 10/10 bien sur.

Commentaire de odysseum le 12/06/2003 16:39:57

Ca à l'air de la balle ton truc là !!! Je teste ça dès mon retour de congés mais déjà je le sens bien après quelques essais !! Bravo !!!

Commentaire de Thorn le 25/08/2003 00:23:23

Excellent job, je pense que sa va bien me servir :)
j'étais en pleine galère..

Commentaire de siddh le 04/09/2003 14:04:48

Franchement super ! On dirait pas comme ça mais tu viens de me sauver la vie :) ...

Commentaire de PROGRAMMIX le 29/09/2003 20:05:00

Je débute au niveau des FTP...

Pourrais-tu mettre un fichier txt (ou autre) dans ton ZIP pour expliquer la manière de procéder ?   J'ai tes réponses aux questions qui t'ont été posées, mais je pense que l'ajout d'un fichier serait bien utile pour les débutants...

Commentaire de EvilGost le 15/03/2006 16:59:50

Comment fonctionne le "ShowError"?
comment sais-t-on s'il y a eu une erreur pendant l'opération?

Commentaire de deeps123 le 17/04/2007 17:46:16

Salut,

Ton programme est super, mais si on veuxfaire un upload d'un dossier en entier?
comment ca se passe?

Commentaire de maww le 11/05/2009 12:31:00

bravo, merci c'est d'une grande utilitée !!!

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,608 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales