Pure FTP

Share your advanced PureBasic knowledge/code with the community.
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Pure FTP

Post by dobro »

I am currently testing the FTP library

I therefore put in mind to make me an FTP client CoreFTP style ....

I discovered that the Lib contains FTP Bugs ... as it does not work for servers FTPPERSO Free!

so I used the function FTPDirectoryEntryRaw ()
to analyze what I get, and I accordingly hack :)

Client is now guaranteed for the server Free.fr (Ftpperso.free.fr)
it can:
list the remote directory
list the local directory

you can walk in the tree remote and local

can Downloader multiple files at once
Upload multiple files can have both
Delete Files can Distant several at a time (no warning .. beware)

It is designed platform (using the API that the window is to display Icons Folder.

the buttons [rename] do not work at the moment ...

against; the progress bar works :)

the log, pass, server, and the position of the window are saved in a file at the close of Preferences program;)
one thing to know, Free Server tends to disconnect us quickly, so it is possible that the time we're looking for the right location
in the branch, we have the server offline! .. Reconnect need to restart .. I did not test if the connection is active :)


in this version ,I do not mind the Folders tree and for transfers ....
list "Queue" works as well as the activity of transfers Appear ...

I completely revised the code to keep only the linked list management by ...



here is it will be a good example of using FTP :)

By cons, try if you are not, in Free.FR, I'd like to know what happens to your FTP ... ;)

Code:

Code: Select all

;***********************************************
;Titre  :*Nouveau
;Auteur  : Dobro
;Date  :28/08/2013
;Heure  :16:12:16
;Version Purebasic :  PureBasic 5.11 (Windows - x86)
;Version de l'editeur :EPB V2.40
; Libairies necessaire : Aucune 
;***********************************************





;{- Enumerations / DataSections
;{ Windows
#Ftp=0
Enumeration
	#Win
EndEnumeration
;}

;{ Gadgets
Enumeration
	#Text_titre
	#ExplorerList_1
	#ExplorerCombo_list1
	#Tree_list2
	#Button_upload
	#Button_Download
	#ListIcon_transfert
	#String_Serveur
	#String_Login
	#String_passwd
	#Button_connection
	#Button_deconnection
	#ProgressBar
	#Text_version
	#String_Local
	#Button_Retour
	#Button_erase
	#Button_rename
	;
	#Text_serv
	#Text_login
	#Text_passwd
	
EndEnumeration
;}
;{ Fonts
Enumeration
	#Font_Text_titre
EndEnumeration
;}



Structure info ;
	win_x.l
	win_y.l
	Serveur.s
	Login.s
	Passwrd.s
	Chemin.s  ; Path Distant affiché dans le String
	Repertoire_local.s
EndStructure
global info.info

Structure info_distant ; fichier distant
	Name.s ; nom du fichier
	size.s ; taille du fichier
	Dat.s ; date du fichier
	Type.l ; dossier ou file
	Chemin.s ; path du fichier
	Repertoire_distant.s ; Path+name.s du fichier
EndStructure
Global Newlist info_distant.info_distant()

Structure info_local ; fichier local
	Name.s ; nom du fichier
	size.s ; taille du fichier
	Dat.s ; date du fichier
	Type.l ; dossier ou file
	Chemin.s ; path du fichier
	Repertoire_local.s ; Path+name.s du fichier
EndStructure
Global Newlist info_local.info_local()

Structure liste
	Chemin.s
	Nom.s
	Taille.s
	Type.l
EndStructure


CompilerIf #PB_Compiler_OS = #PB_OS_Linux
	CompilerElse
	Structure MySHFILEINFO
		hIcon.l
		iIcon.l
		dwAttributes.l
		szDisplayName.b[#MAX_PATH]
		szTypeName.b[80]
	EndStructure
CompilerEndIf


;- Decalration procedures
Declare  Open_Window()
Declare.s list_ftp(dir$)
Declare  Save_pref()
Declare  Load_pref()
Declare  gere_liste_queu(mode.s)

; ********************************************
; Client FTP Codé par Dobro en Purebasic 5.10
; ********************************************


;}

global pos ,tttt,repertoire$,element_local


Open_Window()

InitNetwork()


;- pre_init
AddElement(info_local()):info_local()\chemin.s=GetPathPart(GetGadgetText(#ExplorerList_1))
info\Repertoire_local.s=info_local()\chemin.s ; on recup le chemin du premier element ( ça sera forcement le meme pour tout les autres )
if info\Chemin.s=""
	info\Chemin.s=""
Endif




;{- Event loop
Repeat
	
	
	Select WaitWindowEvent(2)
		; ///////////////////
		Case #PB_Event_Gadget
		Select EventGadget()
			Case #Text_titre
			Case #ExplorerList_1 ; local
			;-Liste_Locale
			;debug GetGadgetText(#ExplorerList_1) ; ok
			;element=GetGadgetState(#ExplorerList_1)
			x=0
			
			Clearlist(info_local())
			for i=0 to CountGadgetItems(#ExplorerList_1 )-1
				;if GetGadgetItemText(#ExplorerList_1, i)<>"" and GetGadgetItemText(#ExplorerList_1, i)<>"." and GetGadgetItemText(#ExplorerList_1, i)<>".."
				if GetGadgetItemState(#ExplorerList_1, i) & #PB_Explorer_Selected
					if GetGadgetItemState(#ExplorerList_1, i) &#PB_Explorer_Directory
						AddElement(info_local())
						info_local()\name.s= GetGadgetItemText(#ExplorerList_1,i) ;ok
						if info_local()\name.s="Nom" : info_local()\name.s="":Endif  ;  <------ parasite ??
						info_local()\chemin.s=GetPathPart(GetGadgetText(#ExplorerList_1))
						info_local()\Repertoire_local.s= GetPathPart(GetGadgetText(#ExplorerList_1)) +info_local()\name.s
						info_local()\size.s="0"
						info_local()\Type.l=2
					Endif
				Endif
				if GetGadgetItemState(#ExplorerList_1, i) &#PB_Explorer_Selected ;#PB_Explorer_Selected&
					if GetGadgetItemState(#ExplorerList_1, i) &#PB_Explorer_File
						AddElement(info_local())
						info_local()\name.s= GetGadgetItemText(#ExplorerList_1,i) ;ok
						if info_local()\name.s="Nom" : info_local()\name.s="":Endif  ;  <------ parasite ??
						info_local()\chemin.s=GetPathPart(GetGadgetText(#ExplorerList_1))
						info_local()\Repertoire_local.s= GetPathPart(GetGadgetText(#ExplorerList_1)) +info_local()\name.s
						info_local()\size.s=str(FileSize(info_local()\Repertoire_local.s) )
						info_local()\Type.l=1
					Endif
				Endif
				;Endif
			Next i
			info\Repertoire_local.s=GetPathPart(GetGadgetText(#ExplorerList_1)) ;
			
			
			Case #ExplorerCombo_list1 ; choix du lecteur
			;-choix_Lecteur
			;debug GetGadgetText(#ExplorerCombo_list1) ; renvoie le lecteur
			SetGadgetText(#ExplorerList_1, GetGadgetText(#ExplorerCombo_list1)) ; ok
			Case #Tree_list2 ; Distant
			;-Liste_Distant
			
			Repertoire$ = GetGadgetText(#Tree_list2)
			
			Select EventType()
				case #PB_EventType_LeftClick 
				;;;debug GetGadgetText(#Tree_list2)
				AddElement(info_distant()):
				info_distant()\name.s=GetGadgetText(#Tree_list2)
				info_distant()\size= GetGadgetItemText(#Tree_list2, GetGadgetState(#Tree_list2),1)
				info_distant()\size=RemoveString(info_distant()\size," ko")
				
				if info_distant()\chemin.s="": info_distant()\chemin.s="":endif
				
				; if info_distant()\name.s=".." or info_distant()\name.s="."
				; info_distant()\name.s=""
				; endif
				
				
				SetGadgetText(#String_Local,info\chemin.s+info_distant()\name.s)
				info_distant()\Repertoire_distant.s=info\chemin.s+info_distant()\name.s ; on pose le repertoire distant dans la structure
				Case #PB_EventType_LeftDoubleClick 
				
				if  info_distant()\type.l<>1   ; c'est un dossier
					ClearGadgetItems(#Tree_list2)
					
					ClearList(info_distant())
					if info\chemin.s="":info\chemin.s="/":Endif
					info\chemin.s=info\chemin.s+list_ftp( Repertoire$)+"/"
					Repertoire$=info\chemin.s
					SetGadgetText(#String_Local,info\chemin.s)
					;info\chemin.s=info_distant(element)\Chemin.s
					
					if FindString(info\chemin.s,"..")=0  and FindString(info\chemin.s,".")=0
						;debug "info:-->"+info\chemin.s
						SetGadgetText(#String_Local,info\chemin.s)
						pos=pos+1
						Else
						;Debug "Remonte"
						;Calldebugger
						pos=pos-1
						info\chemin.s=removestring(info\chemin.s,"../")
						For i=1 to len(info\chemin.s)
							extr$=mid(info\chemin.s,i,1)
							chem$=chem$+extr$
							if extr$="/"
								tttt=tttt+1
								if tttt=pos
									info\chemin.s=chem$
									chem$=""
									tttt=0
									Break
								Endif
								if tttt>Pos
									info\chemin.s="/"
									chem$=""
									tttt=0
									Break
								Endif
							Endif
						Next i
						SetGadgetText(#String_Local,info\chemin.s)
					Endif
				Endif
			EndSelect
			
			
			
			Case #Button_upload
			;- UPLOAD
			; il faut absolument que le nom du fichier apparaisse dans le chemin de destination Et dans le chemin de Depart
			;debug "toto: "+info\chemin.s+GetGadgetItemText(#ExplorerList_1,GetGadgetState(#ExplorerList_1))
			;calldebugger
			Global Newlist liste.liste() ; liste temporaire pour transfert
			ResetList(info_local())
			u=0
			; ajout dans la queue
			While NextElement(info_local())
				AddElement( liste.s()) ; ajout
				Liste.s()\chemin.s =info_local()\chemin.s; le path du fichier local
				Liste.s()\nom.s =info_local()\name.s ; le nom du fichier local
				Liste.s()\taille.s=info_local()\size.s ; la taille du fichier local
				Liste.s()\type.l=info_local()\type.l
				AddGadgetItem(#ListIcon_transfert, u, Liste.s()\nom.s ) ; ajoute dans la queue
				u=u+1
			Wend
			
			; Traitement pour envoi
			ResetList(info_local()):ResetList(liste())
			While NextElement(info_local())
				NextElement(liste())
				debug Liste.s()\nom.s
				if info_local()\type.l<>1
					CreateFTPDirectory(#Ftp, Liste.s()\nom.s) ; on a voulu uploader un dossier , celui ci est cree dans le repertoire distant ... mais ...
					; ici faudrai explorer de façon recursive le dossier avant l'envoi de fichiers ..
					; en attendant ...
					Break
				Endif
				if SendFTPFile(#Ftp, info_local()\repertoire_local.s,info_distant()\Repertoire_distant.s+info_local()\name.s ,#True)
					SetGadgetAttribute(#ProgressBar,  #PB_ProgressBar_Maximum, val(info_local()\size.s))
					if FTPProgress(#Ftp)=#PB_FTP_Started
						repeat
							if isFTP(#ftp)
								if FTPProgress(#Ftp)>0
									SetGadgetState(#ProgressBar, FTPProgress(#Ftp))
									gere_liste_queu("progress")
									WaitWindowEvent(2)
								Endif
								Select  FTPProgress(#Ftp)
									case #PB_FTP_Finished
									;;MessageRequester("Info" , "Upload ok") ; faudra ajouter l'info dans la list des transferts.
									SetGadgetState(#ProgressBar, 0)
									gere_liste_queu("enleve")
									list_ftp(info\chemin.s) ; Rafraichi l'arborescence distante
									Break
									Case #PB_FTP_Error
									MessageRequester("Info" , "UPload error !")  ; faudra ajouter l'info dans la list des transferts.
									SetGadgetState(#ProgressBar, 0)
									Break
								Endselect
							Endif
						Forever
					Endif
					Else
					MessageRequester("Erreur","l'upload ne se produit pas")
				Endif
				
			Wend
			list_ftp(info\chemin.s) ; Rafraichi l'arborescence distante
			FreeList(Liste())
			Case #Button_Download
			;- DOWNLOAD
			;pour un fichier, il faut absolument que le nom du fichier apparaisse dans le chemin de destination Et dans le chemin de Depart
			;;debug info\repertoire_distant ; ok
			;;------------ wget -r ftp://ftp.host.net/thedir/
			;; ------------  wget -r ftp://login:passwd@ftp.host.net/thedir/*
			
			Global Newlist liste.liste() ; liste temporaire pour transfert
			For a=0 To CountGadgetItems(#Tree_list2)-1 ; pour tout les elements de la list_icone on regarde si l'element est selectionné
				if GetGadgetItemState(#Tree_list2, a)=#PB_ListIcon_Selected ; est il selectionné ?
					;;debug GetGadgetItemText(#Tree_list2, a) ; retourne l'element selectionné
					AddElement( liste.s()) ; ajoute le nom du fichier
					Liste.s()\chemin.s =info\chemin.s; le path du fichier distant
					Liste.s()\nom.s =GetGadgetItemText(#Tree_list2, a); le nom du fichier distant
					Liste.s()\taille.s=GetGadgetItemText(#Tree_list2, a,1); la taille du fichier distant
					AddGadgetItem(#ListIcon_transfert, a, Liste.s()\nom.s ) ; ajoute dans la queue
				Endif
			Next a
			
			;calldebugger
			ResetList(Liste.s())
			
			While NextElement(Liste.s())
				;debug Liste.s()\chemin.s+Liste.s()\nom.s
				;debug info\Repertoire_Local +Liste.s()\nom.s
				
				
				if ReceiveFTPFile(#Ftp,Liste.s()\chemin.s+Liste.s()\nom.s, info\Repertoire_Local +Liste.s()\nom.s,#True)
					SetGadgetAttribute(#ProgressBar,  #PB_ProgressBar_Maximum, val(Liste.s()\taille.s))
					if FTPProgress(#Ftp)=#PB_FTP_Started
						repeat
							WindowEvent()
							if isFTP(#ftp)
								SetGadgetState(#ProgressBar, FTPProgress(#Ftp))
								gere_liste_queu("progress")
								
								;debug FTPProgress(#Ftp)
							Endif
							Select  FTPProgress(#Ftp)
								case #PB_FTP_Finished
								;MessageRequester("Info" , "Download ok") ; faudra ajouter l'info dans la list des transferts.
								debug info\Repertoire_Local +Liste.s()\nom.s+".. OK !"
								gere_liste_queu("enleve")
								SetGadgetState(#ProgressBar, 0)
								Break
								Case #PB_FTP_Error
								;MessageRequester("Info" , "Download error !")  ; faudra ajouter l'info dans la list des transferts.
								debug info\Repertoire_Local +Liste.s()\nom.s+".. ERREUR !"
								SetGadgetState(#ProgressBar, 0)
								Break
							Endselect
						forever
					Endif
					
					Else
					MessageRequester("Erreur","le telechargement ne se produit pas")
				Endif
				
			Wend
			FreeList(Liste())
			Case #ListIcon_transfert
			;-Liste Queue
			Case #String_Serveur
			info\Serveur.s=GetGadgetText(#String_Serveur)
			Case #String_Login
			info\Login.s=GetGadgetText(#String_Login)
			Case #String_passwd
			info\passwrd.s=GetGadgetText(#String_passwd)
			Case #Button_connection
			;-connection
			If OpenFTP(#Ftp, info\Serveur.s, info\Login.s, info\Passwrd.s)
				Debug "Connecté avec succès"
				If ExamineFTPDirectory(#ftp)
					list_ftp("/")
					
				EndIf
				HideGadget(#Button_connection,1)
				HideGadget(#Button_deconnection,0)
				Else
				MessageRequester("Erreur","connection non établie",#PB_MessageRequester_Ok          )
			EndIf
			Case #Button_deconnection
			;-Deconnection
			CloseFTP(#Ftp)
			HideGadget(#Button_connection,0)
			HideGadget(#Button_deconnection,1)
			; empty the list gadget
			ClearGadgetItems(#Tree_list2)
			
			Case #Button_Retour
			;-bouton_UP
			HideGadget(#Button_Retour,1)
			element=GetGadgetState(#Tree_list2)
			if element=-1 :element=0:Endif
			info\chemin.s=removestring(info\chemin.s,"../")
			For i=1 to len(info\chemin.s)
				extr$=mid(info\chemin.s,i,1)
				chem$=chem$+extr$
				if extr$="/"
					tttt=tttt+1
					if tttt=pos
						info\chemin.s=chem$
						chem$=""
						tttt=0
						Break
					Endif
					if tttt>Pos
						info\chemin.s="/"
						chem$=""
						tttt=0
						Break
					Endif
					
				Endif
				
			Next i
			pos=pos-1
			SetGadgetText(#String_Local,info\chemin.s)
			list_ftp(info\chemin.s)
			HideGadget(#Button_Retour,0)
			Case  #Button_erase
			;-bouton_erase
			Global Newlist liste.liste() ; liste temporaire
			ResetList (info_distant()) :NextElement(info_distant()) ; on se met sur le premier element
			For a=0 To CountGadgetItems(#Tree_list2) ; pour tout les elements de la list_icone on regarde si l'element est selectionné
				
				if GetGadgetItemState(#Tree_list2, a)=#PB_ListIcon_Selected ; est il selectionné ?
					
					;;debug GetGadgetItemText(#Tree_list2, a) ; retourne l'element selectionné
					AddElement( liste.s()) ; ajoute
					Liste.s()\chemin.s =info_distant()\chemin.s;;info\chemin.s; le path du fichier distant
					Liste.s()\nom.s =info_distant()\name.s;;GetGadgetItemText(#Tree_list2, a); le nom du fichier distant
					Liste.s()\taille.s=info_distant()\size.s;;GetGadgetItemText(#Tree_list2, a,1); la taille du fichier distant
					Liste.s()\type.l=info_distant()\type.l
					AddGadgetItem(#ListIcon_transfert, a, Liste.s()\nom.s ) ; ajoute dans la queue
				Endif
				NextElement(info_distant())
			Next a
			
			;calldebugger
			ResetList(Liste.s())
			
			
			While NextElement(Liste.s()) ; pour chaque element de la liste temporaire
				if liste.s()\type.l=1
					
					if DeleteFTPFile(#Ftp, info\chemin.s+Liste.s()\nom.s )=0
						MessageRequester("erreur", "je ne peux pas effacer "+Liste.s()\nom.s)
						Else
						Beep(440,100) ; ok Effacé
						gere_liste_queu("enleve")
					Endif
					Else
					
					if DeleteFTPDirectory(#Ftp, Liste.s()\chemin.s+Liste.s()\nom.s)=0
						MessageRequester("erreur", "je ne peux pas effacer ("+Liste.s()\nom.s +")"+chr(10)+" ..il est plein.. videz le d'abord")
						Else
						Beep(440,100) ; ok Effacé
						gere_liste_queu("enleve")
					Endif
				Endif
			Wend
			list_ftp(info\chemin.s) ; Rafraichi l'arborescence distante
			FreeList(liste())
			Case   #Button_rename
			;-bouton_rename
			Case #String_Local
			;EndSelect
		EndSelect
		; ////////////////////////
		Case #PB_Event_CloseWindow
		Select EventWindow()
			Case #Win
			info\Serveur.s=GetGadgetText(#String_Serveur)
			info\Login.s=GetGadgetText(#String_Login)
			info\Passwrd.s=GetGadgetText(#String_passwd)
			Save_pref()
			CloseWindow(#Win)
			Break
		EndSelect
	EndSelect
Forever
;²



Procedure Open_Window()
	load_pref()
	
	;-OPEN_WINDOW
	If OpenWindow(#Win, info\win_x, info\win_y,919, 742, "By Dobro", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
		TextGadget(#Text_titre, 410, 10, 189, 53, "Pure FTP")
		
		TextGadget(#Text_version, 440, 70, 111, 24, "V.1.04 By Dobro")
		
		ExplorerComboGadget(#ExplorerCombo_list1, 30, 100, 400, 30, "c:\")
		ExplorerListGadget(#ExplorerList_1, 30, 130, 400, 460, "c:\",#PB_Explorer_MultiSelect)
		SetGadgetItemAttribute(#ExplorerList_1, Element, #PB_Explorer_ColumnWidth, 180 , 0)
		SetGadgetItemAttribute(#ExplorerList_1, Element, #PB_Explorer_ColumnWidth, 80 , 1)
		
		ListIconGadget(#Tree_list2, 480, 120, 360, 470,"liste",180,#PB_ListIcon_MultiSelect )
		AddGadgetColumn(#Tree_list2, 1, "Taille", 90)
		AddGadgetColumn(#Tree_list2, 2, "Date", 90)
		AddGadgetColumn(#Tree_list2, 2, "Activity", 90)
		ButtonGadget(#Button_upload,435, 210, 40, 40, "--->")
		ButtonGadget(#Button_Download,435, 279, 40, 40, "<----")
		ListIconGadget(#ListIcon_transfert, 20, 610, 820, 120, "Name", 500, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
		
		AddGadgetColumn(#ListIcon_transfert, 1, "Activity", 500)
		
		StringGadget(#String_Serveur, 60, 10, 260, 20, "Ftpperso.free.fr")
		StringGadget(#String_Login, 60, 40, 260, 20, "Login")
		StringGadget(#String_passwd, 60, 70, 260, 20, "Passwd",#PB_String_Password)
		TextGadget(#Text_serv, 10, 10, 50, 20, "Serveur")
		TextGadget(#Text_login, 10, 40, 50, 20, "Login")
		TextGadget(#Text_passwd, 10, 70, 50, 20, "Passwd")
		ButtonGadget(#Button_connection, 723, 13, 80, 70, "Connection")
		ButtonGadget(#Button_deconnection,723, 14, 80, 70, "deconnect")
		HideGadget(#Button_deconnection,1)
		; Gadget Fonts
		SetGadgetFont(#Text_titre, LoadFont(#Font_Text_titre, "Arial", 24, #PB_Font_Bold|#PB_Font_HighQuality))
		;
		ProgressBarGadget(#ProgressBar,186, 595, 480, 10, 0, 100, #PB_ProgressBar_Smooth)
		StringGadget(#String_Local, 480, 90, 360, 20, "")
		
		ButtonGadget(#Button_Retour, 850, 120, 50, 50, "Up")
		ButtonGadget(#Button_erase, 850, 510, 50, 20, "Erase")
		ButtonGadget(#Button_rename, 850, 180, 50, 20, "Rename")
		
		; init Gadget
		SetGadgetText(#String_Serveur,info\serveur)
		SetGadgetText(#String_Login,info\Login)
		SetGadgetText(#String_passwd,info\passwrd)
		
	EndIf
EndProcedure

Procedure.s list_ftp(dir$)
	if isFTP(#Ftp)
		CompilerIf #PB_Compiler_OS = #PB_OS_Linux
			dir$=removestring(dir$,"|x|---> ")
			CompilerElse
		CompilerEndIf
		SetFTPDirectory(#ftp, dir$)
		
		
		If ExamineFTPDirectory(#ftp)
			
			ClearGadgetItems(#Tree_list2)
			
			clearlist(info_distant())
			x=0
			
			While NextFTPDirectoryEntry(#ftp)
				
				f$=""
				f$= FTPDirectoryEntryRaw(#Ftp)
				f$=ReplaceString(f$,chr(32),",") :f$=ReplaceString(f$,",,,,,",","):f$=ReplaceString(f$,",,,,",","):f$=ReplaceString(f$,",,,",","):f$=ReplaceString(f$,",,",","):
				;debug f$
				;calldebugger
				AddElement(info_distant()):
				info_distant()\name.s=StringField(f$,9,",")
				info_distant()\size.s=StringField(f$,5,",")
				info_distant()\dat.s=StringField(f$,6,",")+" "+StringField(f$,7," ")+","+StringField(f$,8,",")
				info_distant()\type.l=val(StringField(f$,2,","))
				;file name with no spaces
				info_distant()\name = StringField(f$, 9, ",")
				
				If CountString(f$, ",") > 8
					;file name has spaces
					For i = 10 To CountString(f$, ",") + 1
						info_distant()\name = info_distant()\name + " " + StringField(f$, i, ",")
					Next
					
				EndIf
				
				
				;
				; info_distant()\size = StringField(f$,5,",")
				; info_distant()\dat  = StringField(f$,6,",")+" "+StringField(f$,7," ")+","+StringField(f$,8,",")
				; info_distant()\type = Val(StringField(f$,2,","))
				
				
				if info_distant()\name.s=".." or info_distant()\name.s="."
					info_distant()\size.s="0"
					info_distant()\type.l=888
					info_distant()\repertoire_distant.s=GetGadgetText(#String_Local)
					info_distant()\chemin.s=info\chemin.s
				endif
				info_distant()\repertoire_distant.s=GetGadgetText(#String_Local)
				info_distant()\chemin.s=info\chemin.s
				;if info_distant(x)\repertoire_distant.s="" :info_distant(x)\repertoire_distant.s="/":endif
				x=x+1
			Wend
			
			
			
			FinishFTPDirectory(#ftp)
			;;SortList(info_distant(), #PB_Sort_Descending|#PB_Sort_NoCase)
			SortStructuredList(info_distant(),#PB_Sort_Descending, OffsetOf(info_distant\Type.l), #PB_Sort_long   )
			
			
			
			ResetList(info_distant())
			i=0
			While NextElement(info_distant())
				
				CompilerIf #PB_Compiler_OS = #PB_OS_Linux
					CompilerElse
					SHGetFileInfo_(info_distant()\name.s, 0, @Info2.MySHFILEINFO, SizeOf(MySHFILEINFO), #SHGFI_ICON|#SHGFI_LARGEICON)
				CompilerEndIf
				
				if  info_distant()\type.l<>1  and  info_distant()\type.l<>888 ; c'est un dossier et c'est pas "." ou ".."
					CompilerIf #PB_Compiler_OS = #PB_OS_Linux
						AddGadgetItem(#Tree_list2,i, "|x|---> "+info_distant()\name.s+chr(10)+info_distant()\size.s+" ko"+chr(10)+info_distant()\dat.s)
						CompilerElse
						AddGadgetItem(#Tree_list2,i, info_distant()\name.s+chr(10)+info_distant()\size.s+" ko"+chr(10)+info_distant()\dat.s, Info2\hIcon)
					CompilerEndIf
				Endif
				if  info_distant()\type.l=1 ; c'est un fichier
					AddGadgetItem(#Tree_list2, i, info_distant()\name.s+chr(10)+info_distant()\size.s+" ko"+chr(10)+info_distant()\dat.s)
				Endif
				
				if info_distant()\name.s<>"." and info_distant()\name.s<> ".." ; Dossier
					
					Else ;  (. et ..) ; inactif, car le bouton UP remplace
					CompilerIf #PB_Compiler_OS = #PB_OS_Linux
						;AddGadgetItem(#Tree_list2,i, info_distant()\name.s+chr(10)+info_distant()\size.s+" ko"+chr(10)+info_distant()\dat.s)
						CompilerElse
						;AddGadgetItem(#Tree_list2,i, info_distant()\name.s+chr(10)+info_distant()\size.s+" ko"+chr(10)+info_distant()\dat.s, Info2\hIcon)
					CompilerEndIf
					
					
				Endif
				
				
				
				i=i+1
				
			Wend
			
			ResetList(info_distant())
			While NextElement(info_distant())
				if info_distant()\name.s=".." or info_distant()\name.s="."
					DeleteElement(info_distant())
				Endif
			Wend
			
		Endif
		SetGadgetText(#String_Local,dir$)
		
		ProcedureReturn  dir$
		Else
		MessageRequester("Erreur","la connection n'existe plus")
		ClearGadgetItems(#Tree_list2)
	Endif
EndProcedure



Procedure Save_pref()
	If CreatePreferences("Pure_FTP.prefs")
		PreferenceGroup("Window")
		WritePreferenceLong ("Winx",WindowX(#win))
		WritePreferenceLong ("Winy",WindowY(#win))
		
		
		PreferenceGroup("Log")
		WritePreferenceString ("Serveur",info\Serveur.s)
		WritePreferenceString("Login",info\Login.s)
		WritePreferenceString("Passwrd",info\Passwrd.s)
		ClosePreferences()
	EndIf
	
	
EndProcedure

Procedure Load_pref()
	if  OpenPreferences("Pure_FTP.prefs")
		
		PreferenceGroup("Window")
		info\win_x= ReadPreferenceLong ("Winx", 1)
		info\win_y=ReadPreferenceLong ("Winy", 1)
		
		
		PreferenceGroup("Log")
		info\Serveur.s= ReadPreferenceString ("Serveur", "ftpperso.free.fr")
		info\Login.s=ReadPreferenceString ("Login", "Login")
		info\Passwrd.s=ReadPreferenceString("Passwrd", "Passwrd")
		ClosePreferences()
	Endif
EndProcedure

procedure gere_liste_queu(mode.s)
	; By Dobro
	; ****************Progress******************
	select mode.s
		Case "progress"
		u=0
		While u<CountGadgetItems(#ListIcon_transfert)
			if GetGadgetItemText(#ListIcon_transfert, u)=Liste.s()\nom.s
				SetGadgetItemText(#ListIcon_transfert, u, str(FTPProgress(#Ftp))+"/"+Liste.s()\taille.s,1 )
			Endif
			u=u+1
		Wend
		Case "enleve"
		; *****************Enleve *****************
		u=0
		While u<CountGadgetItems(#ListIcon_transfert)
			if GetGadgetItemText(#ListIcon_transfert, u)=Liste.s()\nom.s
				RemoveGadgetItem(#ListIcon_transfert, u)
			Endif
			u=u+1
		Wend
		; **********************************
	EndSelect
	; **********************************
Endprocedure
;}

; EPB
Last edited by dobro on Wed Aug 28, 2013 3:12 pm, edited 3 times in total.
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Pure FTP

Post by rsts »

Wow. Very nice indeed. :D

Thanks for sharing.

cheers
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Pure FTP

Post by fsw »

First I added:

Code: Select all

         ; empty the list gadget
         ClearGadgetItems(#Tree_list2)
to the disconnect code, so the remote file list is empty.

Second, it doesn't work with files that have spaces in their name, so I had to change this:
(in list_ftp procedure)

Code: Select all

            info_distant()\name.s=StringField(f$,9,",")
            info_distant()\size.s=StringField(f$,5,",")
            info_distant()\dat.s=StringField(f$,6,",")+" "+StringField(f$,7," ")+","+StringField(f$,8,",")
            info_distant()\type.l=val(StringField(f$,2,","))
to this:

Code: Select all

            ;file name with no spaces
            info_distant()\name = StringField(f$, 9, ",")
            
            If CountString(f$, ",") > 8
              ;file name has spaces
              For i = 10 To CountString(f$, ",") + 1
                  info_distant()\name = info_distant()\name + " " + StringField(f$, i, ",")
              Next
              
            EndIf
            
            info_distant()\size = StringField(f$,5,",")
            info_distant()\dat  = StringField(f$,6,",")+" "+StringField(f$,7," ")+","+StringField(f$,8,",")
            info_distant()\type = Val(StringField(f$,2,","))
Somewhere I read that the data that is coming from the ftp server is not standardized, so I don't think simple parsing will work as expected all the time.
It seems to work with comcast though...

BTW: I know I could do:

Code: Select all

info_distant()\name + " " + StringField(f$, i, ",")
but the first stand alone "+" is just weird to me. Other languages use "+="...

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Pure FTP

Post by dobro »

fsw wrote:First I added:

Code: Select all

         ; empty the list gadget
         ClearGadgetItems(#Tree_list2)
to the disconnect code, so the remote file list is empty.
Thank you, I did not, because I found interresting, to continue to see
the contents of the site being not connected



Second, it doesn't work with files that have spaces in their name, so I had to change this:
(in list_ftp procedure)

Code: Select all

            info_distant()\name.s=StringField(f$,9,",")
            info_distant()\size.s=StringField(f$,5,",")
            info_distant()\dat.s=StringField(f$,6,",")+" "+StringField(f$,7," ")+","+StringField(f$,8,",")
            info_distant()\type.l=val(StringField(f$,2,","))
to this:

Code: Select all

            ;file name with no spaces
            info_distant()\name = StringField(f$, 9, ",")
            
            If CountString(f$, ",") > 8
              ;file name has spaces
              For i = 10 To CountString(f$, ",") + 1
                  info_distant()\name = info_distant()\name + " " + StringField(f$, i, ",")
              Next
              
            EndIf
            
            info_distant()\size = StringField(f$,5,",")
            info_distant()\dat  = StringField(f$,6,",")+" "+StringField(f$,7," ")+","+StringField(f$,8,",")
            info_distant()\type = Val(StringField(f$,2,","))
Thanks for this :)
Somewhere I read that the data that is coming from the ftp server is not standardized, so I don't think simple parsing will work as expected all the time.
It seems to work with comcast though...
yes, FREE.FR, I could not use the features of PureBasic
as "FTPDirectoryEntryType(#Ftp)"
That is why I used FTPDirectoryEntryRaw(#Ftp) :)

Thank you for these changes, I'll put the code up to date :)
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Pure FTP

Post by dobro »

small change in the code of the first page :)

I have not included the recursion for the exploration of issues but ...

I added to the upload the Create Folder"Empty" ...
which can then, in a second time to Upload Files in these folders created, and so fill them

for Erase (still remote), you can not delete a folder "Fill" but ... can enter the folder, select all files
the eraser, then remove the file now "empty", then you can delete these files or what items ..

which go anyway, exploitable code in use every day ..

of course taking into account of the tree will be more ... but to tell you the truth, I'm a little laziness to continue .. : lol:
I return Tracmania Forever ... and my black Audi R8 :)
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: Pure FTP

Post by VB6_to_PBx »

Code: Select all

;Beep(440,100) ; ok Effacé
gives Error in english text version ??

translation
Beep not showing up in PureBasic Help ?
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Pure FTP

Post by fsw »

VB6_to_PBx wrote:

Code: Select all

;Beep(440,100) ; ok Effacé
gives Error in english text version ??

translation
Beep not showing up in PureBasic Help ?
That's because Beep is a WIndowsAPI command.
The proper way of using it would be:

Code: Select all

;Beep_(440,100) ; ok Effacé

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: Pure FTP

Post by VB6_to_PBx »

fsw wrote:
VB6_to_PBx wrote:

Code: Select all

;Beep(440,100) ; ok Effacé
gives Error in english text version ??

translation
Beep not showing up in PureBasic Help ?
That's because Beep is a WIndowsAPI command.
The proper way of using it would be:

Code: Select all

;Beep_(440,100) ; ok Effacé

Beep(440,100)
Beep_(440,100) ; this works :D

i use Google Translator, and sometimes it does not know how to handle
certain characters properly .
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Pure FTP

Post by SFSxOI »

very nice :)

heck, I did not even consider that people still use FTP now a days. I haven't used an FTP server for a while.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Pure FTP

Post by dobro »

home Beep (440.100) works, maybe, because of a resident or
pbi
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
Post Reply