get FTP file list include all subfolder and download

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
syana
In need of some credit
In need of some credit
Posts: 1
Joined: Wed Feb 18, 2009 3:02 am

get FTP file list include all subfolder and download

Post by syana » Wed Feb 18, 2009 3:34 am

Hi There,

I'm new user of wxWidget.
I want to display all the files of a folder (including those in subfolders) located on a FTP server. Then download some of them.

I have 2 problems:

1. How to display ALL the files?
If I use wxFTP::GetDirList or wxFTP::GetFilesList, I only have the files in the folder, not those in subfolders.
Can I use function which are not in wxFTP such as wxDir::GetAllFiles? In this case, in "dirname" should I only write the name of the directory or also add the hostname?

2. When I try to download a file after being connected, I 've got ERROR: "Failed to set transfer mode to binary" How to solve that?

This is my code:

Code: Select all

static void TestFtpDownload(wxTextCtrl *m_textrich)
{
        wxString filename = _T("readme.txt"); 

	wxInputStream *in = ftp.GetInputStream(filename);

	if ( !in )
	{
		wxMessageBox(filename, _T("ERROR: couldn't get input stream for"), wxOK, NULL) ;
	}
	else
	{
		size_t size = in->GetSize();
		wxMessageBox(filename ,_T("Reading file") ,  wxOK, NULL) ;
		fflush(stdout);

		wxChar *data = new wxChar[size];
		if ( !in->Read(data, size) )
		{
			wxMessageBox(_T("RESULT"), _T("Read Error"), wxOK, NULL) ;
		}
		else
		{
			m_textrich->AppendText(data);
		}

		delete [] data;
		delete in;
	}
}

Please help me!
Thanks

computerquip
Experienced Solver
Experienced Solver
Posts: 72
Joined: Fri Feb 20, 2009 7:13 pm
Location: $(#wx)\src

Post by computerquip » Wed Feb 25, 2009 5:31 pm

Normally people wouldn't want to list ALL folder, subfolders, subsubfolders, etc. because it can lead up to HUGE amounts of output. Shit, if I did that on my CQPrograms directory, I'd probably be there for days! And to be quite honest, in Linux, I could make a script that runs through a loop and subdirectories determining whether something is a folder and if so list folders and files within and so on and so on etc. But, I don't see the ability to list specific directories inside of the wxGetList function or other similar functions. As a result, you'd probably not be able to unfortunately (at least through wxFTP). The best thing I can think of is maybe make something that would change to each directory and then call the GetDirList function.
(^ the above may not all be true due to my lack of knowledge in the subject)

Also, for the second problem, I don't see anything that connects to a server. I also don't even see where you construct a wxFTP class.
http://docs.wxwidgets.org/stable/wx_wxf ... getdirlist
At the bottom is an example similar to yours. Try and compare it and see if you can figure it out.

Post Reply