FTPClient - Listing all files

Post

Posted
Rating:
#1 (In Topic #1321)
Regular
monteiro is in the usergroup ‘Regular’
 Good morning.
How can I put on a Listview all PDF files that exist in the FTP server using the FTPClient?

Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
I do not have any ready-made code but it's pretty simple.

Just send a list command and process the results

What have you tried?

Do you know anything about sending FTP commands?
Basic FTP Commands
File Transfer Protocol (FTP), a List of FTP Commands

Use FtpClient.Exec() to send a command to list the directory and its _Read event for the results.

Do you know how to populate a ListView?
/comp/gb.qt4/listview/add - Gambas Documentation

if the ftp server has directory listing mode enabled (can be viewed in a browser) then possibly easier to simply use httpClient.Download() on the directory and process the page.
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
monteiro is in the usergroup ‘Regular’
 Thank you Bruce.

I'm struggling a lot to process the result and populate the control.
I'm going to go back to a tactic I've used before, creating a shell script to connect to the server, navigate to the desired directory and save the file names to a local text file.

Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
monteiro is in the usergroup ‘Regular’
 As I am just interested on PDF files, this has worked fine using curl:

Dim sLine As String

  ListBox1.Clear
  If Exist(Application.Path & "/arquivos") Then Kill Application.Path & "/arquivos"
  Shell "curl –list-only ftp://" & user & ":" & pass & "@192.168.5.254 >" & Application.Path & "/arquivos"
  Wait 2
  hFile = Open Application.Path & "/arquivos" For Read
  While Not Eof(hFile)
    Line Input #hFile, sLine
    If Right(sLine, 4) = ".pdf" Or Right(sLine, 4) = ".PDF" Then ListBox1.Add(sLine)
  Wend
  Close #hFile

Online now: No Back to the top
1 guest and 0 members have just viewed this.