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)
> 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
Try looking at wxFTP::GetDirList and GetFileList there is also FileExists.
On Jun 15, 9:03 pm, Gadget/Steve <GadgetSt...@live.co.uk> wrote:
> On 15/06/2012 1:28 PM, evstevemd wrote:> 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
> Try looking at wxFTP::GetDirList and GetFileList there is also FileExists.
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.
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);
}
}
> 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);
> }
> }
> 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);
> }
> }
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.
> > 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);
> > }
> > }
> 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.
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