Ftp client such as Bobdown

Just starting out? Need help? Post your questions and find answers here.
lazy
New User
New User
Posts: 7
Joined: Tue Nov 04, 2003 4:23 pm

Ftp client such as Bobdown

Post by lazy »

All is in the title,
I would like to create a FtpClient such as BobDown! Only a client, which connect to a server, go to a path and list the directory!

I know it's not very difficult but i'm a naab :(

Someone can help me?
thx
Laz`76
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Search the forum for FTP and start reading. There are several examples of FTP type commands.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
lazy
New User
New User
Posts: 7
Joined: Tue Nov 04, 2003 4:23 pm

Post by lazy »

I've already checked the forum, I'm know how to connect to a Ftp but i've a problem when i want to change the directory! If there was a space in the path, my prog break!
Could you help me?
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Post some code and someone here probably can..
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
lazy
New User
New User
Posts: 7
Joined: Tue Nov 04, 2003 4:23 pm

Post by lazy »

That the procedure :

Code: Select all

#INTERNET_SERVICE_FTP = 1 
#INTERNET_OPEN_TYPE_DIRECT = 1             
#Verzeichniss = 16 
#Datei = 128 

NewList FindFileData.WIN32_FIND_DATA() 

Procedure GetFTPdirectory(hConnect.l, Pfad$) 
  AddElement(FindFileData()) 
  hFind.l = FtpFindFirstFile_(hConnect, Pfad$ + "*", @FindFileData(), 0, 0) 
  AddElement(FindFileData()) 
  While InternetFindNextFile_(hFind , @FindFileData()) 
    AddElement(FindFileData()) 
  Wend 
  DeleteElement(FindFileData()) 
  InternetCloseHandle_(hFind) 
EndProcedure 

Procedure PrintFileData() 
  Name$ = PeekS(@FindFileData()\cFileName) 
  Select FindFileData()\dwFileAttributes 
    Case #Datei 
      Size.l = FindFileData()\nFileSizeLow + FindFileData()\nFileSizeHigh<<8 
      AddGadgetItem(#Gadget_2, -1,(Name$ + "    " + Str(Size) + " bytes")) 
    Case #Verzeichniss 
      If Name$ <> "." And Name$ <> ".." 
        AddGadgetItem(#Gadget_2, -1,("/" + Name$ + "/"))
      EndIf 
    Default 
      Debug "unbekannter Attributwert: " + Str(FindFileData()\dwFileAttributes) 
  EndSelect 
EndProcedure 

Procedure GetFTPinfo() 
  InternetGetLastResponseInfo_(@lpdwError.l, 0, @lpdwBufferLength.l) 
  If lpdwBufferLength > 0 
    lpszBuffer$ = Space(lpdwBufferLength) 
    If InternetGetLastResponseInfo_(@lpdwError, @lpszBuffer$, @lpdwBufferLength) 
      CRLF$ = Chr(13) + Chr(10) 
      posA.l = FindString(lpszBuffer$, CRLF$, 0) 
      If posA 
        AddGadgetItem(#Gadget_7, 0, (Left(lpszBuffer$, posA - 1)))
        StatusBarText(0, 1, (Left(lpszBuffer$, posA - 1)), #PB_StatusBar_BorderLess)
        UpdateStatusBar(0)
        posA + 2 
        posB.l = FindString(lpszBuffer$, CRLF$, posA) 
        While posB 
          AddGadgetItem(#Gadget_7, 0,(Mid(lpszBuffer$, posA, posB - posA)))
          StatusBarText(0, 1, (Mid(lpszBuffer$, posA, posB - posA)), #PB_StatusBar_BorderLess)
          UpdateStatusBar(0)
          posA = posB + 2 
          posB = FindString(lpszBuffer$, CRLF$, posA)          
        Wend 
      Else 
        AddGadgetItem(#Gadget_7, 0,(lpszBuffer$))
        StatusBarText(0, 1, (lpszBuffer$), #PB_StatusBar_BorderLess)
        UpdateStatusBar(0)
      EndIf 
    EndIf 
    ;AddGadgetItem(#Gadget_7, -1, "") 
  EndIf 
EndProcedure 
But when there are spaces in the path, that break!
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Re: Ftp client such as Bobdown

Post by TerryHough »

lazy wrote:I would like to create a FtpClient such as BobDown! Only a client, which connect to a server, go to a path and list the directory!
Take a look at forum topic <a href="viewtopic.php?t=12656&">FTP for all PB OS's</a>

Num3's library and/or include file provides a way to do FTP access using
the PB Networking commands. It is pretty easy to do what you want
using only PB commands.

Here is my modified code for FTP_Dirlist() and an additonal
FTP_DirDisplay() to display the results in a ListIconGadget.

Code: Select all

Procedure FTP_DirList()
  FTP_Last_Message = ""
  If ConnectionID
    Repeat
      ConnectionID_event = NetworkClientEvent(ConnectionID)
      Select ConnectionID_event
      Case 2
        In.s = Space(57344)
        result = ReceiveNetworkData(ConnectionID, @In, Len(In))
        If result > 0
          FTP_Last_Message + Trim(In.s)
          time.l = Date()
          ; OpenFile(2,"dirlist.txt")
          ; WriteData(@In,result)
          ; CloseFile(2)
        EndIf
      Case 0
        ; Directory listing has been received, optionally show a formatted list
        ; MessageRequester("Debug - Dir_List",Trim(In),0)
        Int_FTP_PASV_CLOSE()
        ProcedureReturn #FTP_OK
      EndSelect
    ForEver
  Else
    ProcedureReturn #FTP_ERROR
  EndIf
EndProcedure

Procedure FTP_DirDisplay(gadget)
  If ListArg$ = ""
    DirEntry$ = Trim(In)
    Repeat
      If DirEntry$
        Temp = FindString(DirEntry$,"ftp",1)
        Temp = FindString(DirEntry$,"ftp",temp + 3)
        DirEntry$ = Trim(Mid(DirEntry$, Temp + 3, Len(DirEntry$)))
        file_size.l = Val(DirEntry$)
        FileName$ = StringField(DirEntry$, 6, " ")
        Temp = FindString(FileName$, Chr(13), 1)
        FileName$ = Trim(Mid(FileName$, 1, Temp - 1))
        If FileName$ = ""
          FileName$ = StringField(DirEntry$, 5, " ")
          Temp = FindString(FileName$, Chr(13), 1)
          FileName$ = Trim(Mid(FileName$, 1, Temp - 1))
        EndIf
        FileType$ = LCase(StringField(FileName$,2,"."))
        FileName$ = RemoveString(FileName$,"." + FileType$,1)
        If file_size
          AddGadgetItem(gadget, -1, Chr(10) + FileName$ + Chr(10) + FileType$ + Chr(10) + Str(file_size))
          SendMessage_(GadgetID(gadget), #LVM_ENSUREVISIBLE,  CountGadgetItems(gadget) - 1, 0) ; Center justify column
          While WindowEvent() : Wend
          FileType$ = ""
          FileName$ = ""
        EndIf
        DirEntry$ = Trim(Mid(DirEntry$, Temp + 3, Len(DirEntry$)))
      EndIf
    Until Len(DirEntry$) = 0
  EndIf
EndProcedure
Good luck,
Terry
lazy
New User
New User
Posts: 7
Joined: Tue Nov 04, 2003 4:23 pm

Post by lazy »

thx
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

If you decide to go the FTP for all PB OS's route you can do what you ask here and in post viewtopic.php?t=8971
and lots more.

Here is a screenshot of the FTP for all PB OS's example program as I updated it.
Log in,
make directory, change to new directory,
upload a file,
get the remote directory info,
display a sortable listing of the remote directory,
download a file,
delete a file,
change back to entry directory,
deletes the created directory,
log out.

Image
Post Reply