il y a deux façons de faire :
1/ passer par les fonctions windows toutes faites
2/ envoyer soi meme les commandes au serveur ftp (list, user, ...)
voici un exemple (je m'y étais essayé aussi) pour la méthode 1/
en s'aidant des fonctions windows décrites sur msdn :
http://msdn2.microsoft.com/en-us/library/aa385473.aspx
l'intérêt de cet exemple est de construire une arborescence du dossier ftp voulu ce qui implique l'utilisation d'une fonction récursive : FtpListAll().
Code : Tout sélectionner
;============================================
EnableExplicit
#FTP_TRANSFER_ASCII = 1
#FTP_TRANSFER_BINARY = 2
#INTERNET_SERVICE_FTP = 1
#INTERNET_OPEN_TYPE_DIRECT = 1
Import "shlwapi.lib"
StrFormatByteSize64A(Size.q, *BufStr, BufSize.l)
EndImport
Procedure.s StrByteSize(nBytes.q)
Protected string.s{64}
If StrFormatByteSize64A(nBytes, @string, 64)
ProcedureReturn PeekS(@string, -1, #PB_Ascii)
EndIf
EndProcedure
Procedure.l FileIcon(Path.s)
Protected info.SHFILEINFO
If SHGetFileInfo_(@Path, #Null, @info, SizeOf(SHFILEINFO), #SHGFI_ICON|#SHGFI_SMALLICON)
ProcedureReturn info\hIcon
EndIf
EndProcedure
Procedure.l FreeIcon(hIcon.l)
If hIcon
DestroyIcon_(hIcon)
EndIf
EndProcedure
;============================================
Structure FILESIZE
High.l
Low.l
EndStructure
Structure WIN32_FIND_DATA_2
dwFileAttributes.l
ftCreationTime.FILETIME
ftLastAccessTime.FILETIME
ftLastWriteTime.FILETIME
nFileSizeLow.l
nFileSizeHigh.l
dwReserved0.l
dwReserved1.l
cFileName.s{260} ; replaced by fixed string
cAlternate.s{14} ; replaced by fixed string
dummy.w
EndStructure
Macro FtpOpen(Proxy = "", ProxyBypass = "")
InternetOpen_("FTP", #INTERNET_OPEN_TYPE_DIRECT, Proxy, ProxyBypass, 0)
EndMacro
Macro FtpClose(hInternet)
InternetCloseHandle_(hInternet)
EndMacro
Macro FtpConnect(hInternet, Host, User, Pwd, Port = 21)
InternetConnect_(hInternet, Host, Port, User, Pwd, #INTERNET_SERVICE_FTP, 0, 0)
EndMacro
Macro FtpDisconnect(hConnect)
InternetCloseHandle_(hConnect)
EndMacro
;============================================
Procedure.l FtpListAll(hConnect.l, folder.s = "/", depth.l = 0)
Protected hIcon.l, hFind.l, Size.q, NewList find.WIN32_FIND_DATA_2()
If FtpSetCurrentDirectory_(hConnect, folder) And AddElement(find())
hFind = FtpFindFirstFile_(hConnect, 0, find(), 0, 0)
If hFind
While AddElement(find()) And InternetFindNextFile_(hFind, find())
; Delay(1)
Wend
InternetCloseHandle_(hFind)
DeleteElement(find())
EndIf
EndIf
ForEach find()
If find()\dwFileAttributes & #FILE_ATTRIBUTE_DIRECTORY
AddGadgetItem(0, -1, find()\cFileName, hIcon, depth)
FtpListAll(hConnect, folder + find()\cFileName + "/", depth + 1)
Else
PokeL(@Size + 4, find()\nFileSizeLow)
PokeL(@Size + 0, find()\nFileSizeHigh)
AddGadgetItem(0, -1, find()\cFileName + " (" + StrByteSize(Size) + ")", hIcon, depth)
EndIf
Next
EndProcedure
;============================================
Define ftp.l, conn.l
If OpenWindow(0, 0, 0, 640, 480, "Ftp", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
TreeGadget(0, 10, 10, 620, 460, #PB_Tree_AlwaysShowSelection)
EndIf
ftp = FtpOpen()
If ftp
;conn = FtpConnect(ftp, "localhost", "user1", "*******")
conn = FtpConnect(ftp, "localhost", "user2", "*******") ; <------------ changer cette ligne
If conn
FtpListAll(conn, "/")
FtpDisconnect(conn)
EndIf
FtpClose(ftp)
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow: Break
Case #PB_Event_SizeWindow: ResizeGadget(0, #PB_Ignore, #PB_Ignore, WindowWidth(0)-20, WindowHeight(0)-20)
EndSelect
ForEver
EndIf
;============================================