This sample show howto use ftp commands from HBTIP library , is not a complete ftp but is functional.
Este Ejemplo muestra como usar los comandos ftp de la libreria HBTIP , no es un ftp completo pero funciona bien.
Surely it have errors , I do not pretend more that an example of what you can do using marinas.
Seguramente tiene errores , no pretendo que sea mas que un ejemplo de lo que se puede hacer con Marinas.
Once connected you can enter to a folder using double click
Una vez conectado con doble click sobre una carpeta pueden bajar un nivel
You can Download a file using contextual menu or Download toolbar button
Ud puede descargar un archivo usando el menu contextual o el boton de la toolbar
This is the source code , you can donload it from here
Este es el codigo fuente , lo pueden descargar aqui ftp.rar
FTP Client Sample Using HBTIP Library | |
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 |
// Sample of use of HBTIP library and marinas-Gui // Ftp Client Sample // Bruno Luciani - 2011 #include "marinas-gui.ch" Function main() Public oFTP Public arr_Files str_LocalPath := mg_GetCurrentFolder() CREATE WINDOW ftpclient ROW 0 COL 0 WIDTH 680 HEIGHT 600 CAPTION "FTP Client Marinas-GUI Sample" ICON "marinas-gui_png" MAIN .T. mtoolbar() mstatusbar() CREATE LABEL Label1 ROW 8 COL 20 WIDTH 100 VALUE "Ftp://" FONTBOLD .T. FONTCOLOR {0,0,255} END LABEL CREATE TEXTBOX URL ROW 10 COL 60 WIDTH 300 VALUE "ftp.mozilla.org" ONENTER connect(mg_get("ftpclient","url","value")) END TEXTBOX CREATE LABEL Label2 ROW 40 COL 20 WIDTH 60 VALUE "User:" FONTBOLD .T. FONTCOLOR {0,0,255} END LABEL CREATE TEXTBOX user ROW 40 COL 60 WIDTH 80 VALUE "anonymous" ONENTER connect(mg_get("ftpclient","url","value")) END TEXTBOX CREATE LABEL Label3 ROW 40 COL 160 WIDTH 60 VALUE "Password" FONTBOLD .T. FONTCOLOR {0,0,255} END LABEL CREATE TEXTBOX password ROW 40 COL 240 WIDTH 100 VALUE "password" ONENTER connect(mg_get("ftpclient","url","value")) END TEXTBOX CREATE Grid Lista ROW 90 COL 60 WIDTH 520 HEIGHT 300 ITEMS { } VALUE 1 FONTNAME "mg_monospace" FONTSIZE 10 FONTCOLOR {0,0,255} TOOLTIP "List of ftp files" FONTBOLD .T. BACKCOLOR {120,120,80} COLUMNHEADERALL {'Name','Size'} COLUMNWIDTHALL {390,90} COLUMNALIGNALL {Qt_AlignLeft ,Qt_AlignCenter} ONDBLCLICK verifica(mg_Get( "ftpclient" , "Lista" , "value" ) ) CREATE CONTEXT MENU CREATE ITEM "Descargar" ONCLICK { || descargar(mg_Get( "ftpclient" , "Lista" , "value" ) ) } PICTURE "../resource/down.png" END ITEM CREATE ITEM "Borrar" ONCLICK { || borrar(mg_Get( "ftpclient" , "Lista" , "item",mg_Get( "ftpclient" , "Lista" , "value" ) )) } PICTURE "../resource/remove.png" END ITEM CREATE ITEM "Crear Carpeta" ONCLICK { || newfolder() } PICTURE "../resource/add.png" END ITEM END MENU END grid CREATE LABEL info ROW 430 COL 60 WIDTH 400 VALUE "Connection Status ?" FONTBOLD .T. FONTCOLOR {255,0,0} END LABEL CREATE LABEL info2 ROW 10 COL 370 WIDTH 250 VALUE "Messages" FONTBOLD .T. FONTCOLOR {255,0,0} END LABEL CREATE BUTTON Button1 ROW 430 COL 450 WIDTH 80 CAPTION "Connect" ONCLICK connect(mg_get("ftpclient","url","value")) END BUTTON CREATE BUTTON Button2 ROW 430 COL 560 WIDTH 80 CAPTION "Disconnect" ENABLED .F. ONCLICK disconnect(oFTP) END BUTTON END WINDOW mg_Do( "ftpclient" , "center" ) mg_Do( "ftpclient" , "activate" ) mg_Do( "ftpclient" , "lista" , "ColumnsAutoFitH" ) Return .T. // Toolbar creation function Function mtoolbar() CREATE TOOLBAR myTollbar TOOLTIP "ToolBar Controls" CREATE TOOLBUTTON ToolBar_Button_1 CAPTION "Stop" TOOLTIP "Button Exit Tooltip" ONCLICK disconnect() PICTURE "resource/remove.png" END TOOLBUTTON TOOLBARSEPARATOR CREATE TOOLBUTTON ToolBar_Button_2 CAPTION "Add Folder" TOOLTIP "Add new Folder" ONCLICK newfolder() PICTURE "resource/add.png" END TOOLBUTTON TOOLBARSEPARATOR CREATE TOOLBUTTON ToolBar_Button_3 CAPTION "Donwload" TOOLTIP "Download Highlighted File" ONCLICK descargar(mg_Get( "ftpclient" , "Lista" , "value" ) ) PICTURE "resource/down.png" END TOOLBUTTON TOOLBARSEPARATOR CREATE TOOLBUTTON ToolBar_Button_4 CAPTION "Back" TOOLTIP "Back to Previous Folder" ONCLICK up() PICTURE "resource/back.png" END TOOLBUTTON TOOLBARSEPARATOR CREATE TOOLBUTTON ToolBar_Button_5 CAPTION "About" TOOLTIP "About FTP Client" ONCLICK mg_MsgInfo( "Marinas Version :"+ mg_Version() + hb_osnewline() + "Bruno Luciani - 2011" ) PICTURE "resource/info.png" END TOOLBUTTON TOOLBARSEPARATOR END TOOLBAR Return .T. // StatusBar creation function Function mstatusbar() CREATE STATUSBAR CAPTION "Marinas-Gui StatusBar Ready !!!" TOOLTIP "StatusBar ToolTip" END STATUSBAR Return .T. FUNCTION connect(cServer) LOCAL aFiles LOCAL cUrl LOCAL cStr LOCAL lRetorno := .T. LOCAL oUrl LOCAL cUser // LOCAL cServer LOCAL cPassword // LOCAL cFile := "" // cServer := "ciencias.uis.edu.co" /* change ftpserver to the real name or ip of your ftp server */ cUser := mg_get("ftpclient","user","value") //"anonymous" /* change ftpuser to an valid user on ftpserer */ cPassword := mg_get("ftpclient","password","value") //"pepe" /* change ftppass to an valid password for ftpuser */ cUrl := "ftp://" + cUser + ":" + cPassword + "@" + cServer mg_set("ftpclient","Button1","enabled",.F.) mg_set("ftpclient","Button2","enabled",.T.) IF !EMPTY(cServer) oUrl := tUrl():New( cUrl ) oFTP := tIPClientFtp():New( oUrl, .T. ) oFTP:nConnTimeout := 20000 oFTP:bUsePasv := .T. DO EVENTS /* Comprobamos si el usuario contiene una @ para forzar el userid */ IF At( "@", cUser ) > 0 oFTP:oUrl:cServer := cServer oFTP:oUrl:cUserID := cUser oFTP:oUrl:cPassword := cPassword ENDIF if oFTP:Open( cUrl ) mg_set("ftpclient","info","value","Conected with: "+cServer) DO EVENTS oFTP:cwd("pub") oFTP:pwd() mg_set("ftpclient","info2","value","Conected with: "+oFTP:creply) // mg_set("ftpclient","info2","value","Descargando Archivo !!") DO EVENTS arr_Files := oFTP:listFiles() int_Files := Len( arr_Files ) cargalista() ELSE cStr := "Could not connect with FTP server" + " " + oURL:cServer IF oFTP:SocketCon == NIL cStr += Chr( 13 ) + Chr( 10 ) + "Conexion not initialized" ELSEIF hb_InetErrorCode( oFTP:SocketCon ) == 0 cStr += Chr( 13 ) + Chr( 10 ) + "Server Response:" + " " + oFTP:cReply ELSE cStr += Chr( 13 ) + Chr( 10 ) + "Conection error :" + " " + hb_InetErrorDesc( oFTP:SocketCon ) ENDIF mg_set("ftpclient","info","value",cStr) DO EVENTS lRetorno := .F. ENDIF ENDIF RETURN lRetorno function disconnect() oFTP:close() mg_set("ftpclient","info2","value","Disconnected !!") mg_set("ftpclient","info","value","Disconnected !!") mg_set("ftpclient","Button1","enabled",.T.) mg_set("ftpclient","Button2","enabled",.F.) DO EVENTS return function cargalista FOR ii = 1 TO int_Files str_ThisFileName := arr_Files[ii][1] // hangs if we allow zero legth files hence following conditional IF arr_Files[ii][2] > 0 mg_do("ftpclient","lista","additem",{arr_files[ii] [1] , arr_Files[ii] [2]}) ENDIF NEXT return Function Verifica(nValue) if empty(nValue) mg_msgstop("No file selected !!") return .F. Endif oFTP:cwd(arr_Files[nValue][1]) oFTP:pwd() mg_set("ftpclient","info2","value","Conected with: "+oFTP:creply) arr_Files := oFTP:listFiles() int_Files := Len( arr_Files ) mg_do("ftpclient","lista","deleteallitems") cargalista() return function descargar(nValue) if empty(nValue) mg_msgstop("No file selected !!") return .F. Endif str_ThisFileName:=arr_Files[nValue][1] str_TargetLocation := str_LocalPath + "/" + str_ThisFileName if oFTP:downloadFile( str_TargetLocation,str_ThisFileName ) mg_msginfo("Downloaded: "+Str_ThisFileName) endif Return .T. function borrar(cFIle) mg_msginfo("Deleting: "+cFile) oFTP:dele(alltrim(cFile)) mg_msginfo("File "+cFile+"Deleted") return .T. function newfolder() cFolder:= mg_InputDialog("New Folder" , "Input folder name :" , "", .F. ) cInfo := oFTP:MKD(cFolder) mg_msginfo(cInfo) return .T. function up() oFTP:cwd("..") oFTP:pwd() mg_set("ftpclient","info2","value","Conected with: "+oFTP:creply) arr_Files := oFTP:listFiles() int_Files := Len( arr_Files ) mg_do("ftpclient","lista","deleteallitems") cargalista() return |