trick to differentiate FTP files and Folders?

66 views
Skip to first unread message

evstevemd

unread,
Jun 15, 2012, 8:28:59 AM6/15/12
to wx-users
I'm using wxFTP and it works wonderfully. However I need to know how
to retrieve files only or folders only.
Checking with FTP have got not way and I'm not sure if there are
similar functionality to file system checks (wxDirExists and the
like).

I have no idea how to do that and I'm new to world of FTP (being using
FileZilla for FTP works)

TIA,
Stefano

Gadget/Steve

unread,
Jun 15, 2012, 2:03:55 PM6/15/12
to wx-u...@googlegroups.com
Try looking at wxFTP::GetDirList and GetFileList there is also FileExists.

Gadget/Steve

evstevemd

unread,
Jun 15, 2012, 4:32:38 PM6/15/12
to wx-users
Thanks Mr. Steve, I guess I have to go with
if(!filename.IsEmpty()){

if(ftp.FileExists(filename)){
//it is a file
}
}else{
//it is a folder
}

}

If there is better way, I would appreciate to a comment.
>
> Gadget/Steve

evstevemd

unread,
Jun 15, 2012, 4:47:48 PM6/15/12
to wx-users
Tried to list folders only using function below unsucessfully. It
seems that FileExists check for existing file or folder

On FTP commandline I get:
ftp> ls -l
200 PORT command successful
150 Opening ASCII mode data connection for file list
drwxr-xr-x 2 root root 4096 Mar 6 2009 ftp
drwx------ 2 root root 16384 Mar 5 2009 lost+found
drwxrwxr-x 118 bake 102 4096 Dec 14 2011 pub
226 Transfer complete

Here is part of the function
wxArrayString folders;
unsigned int i;
for(i=0; i<folders.GetCount(); i++) {
if(!folders[i].IsEmpty() && !m_ftp.FileExists(folders[i])) {
//it is folder
m_ftp.GetDirList(folders);
m_folders->Set(folders);
}
}

evstevemd

unread,
Jun 16, 2012, 3:02:32 AM6/16/12
to wx-users
Please ignore this code. I was overpowered by sleepness that I posted
something as useless as this one!

Gadget/Steve

unread,
Jun 16, 2012, 3:22:25 AM6/16/12
to wx-u...@googlegroups.com
The problem with the above fragment is that folders.GetCount() is that
it will always return zero as there is no GetDirList outside of it -
also I have found that FTP commands generally only work on the current
remote directory i.e. you need to chdir first so for example to get a
count of all the files, (not directories), on the remote system you
could use something like:

int GetFileCount(wxString SubDir="/", wxString WCard="")
{
/* WARNING UNTESTED CODE Not sure it will even compile */
wxArrayString FileList;
wxArrayString DirList;
int FileCount = 0;
int n;

m_ftp.ChDir(SubDir); // Change the remote directory to the
sub-directory
m_ftp.GetFileList(&FileList, WCard); // Get the file list
FileCount = FileList.GetCount(); // Get the File count in the directory
for (n = 0; n < DirList.GetCount(); n++) // Handle the sub-directories
{
FileCount += GetFileCount(DirList[n], WCard); // Recursive call
}
m_ftp.ChDir("..") // Back to where we were IMPORTANT
return (FileCount) // Return the file count for the specified sub
directory
}

Hope that is some help. If it works ok you could use it as a template
for a function that would get all the files that match a given wildcard,
etc.

Gadget/Steve

evstevemd

unread,
Jun 16, 2012, 3:37:30 AM6/16/12
to wx-users
Thanks a lot!

evstevemd

unread,
Jun 21, 2012, 5:53:38 AM6/21/12
to wx-users
It seems there is no way of distinguishing folder from file in FTP
(and so in wxFTP) but what suprises me is that filezilla handles it
well.
Filezilla have good chunk of code and so it will take time to get the
trick but if any have a way of doing it and is willing to share, I
will appreciate it!
TIA,
Stefano
Reply all
Reply to author
Forward
0 new messages