Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » File List with FtpClient
File List with FtpClient [message #12175] Mon, 15 October 2007 11:05 Go to next message
WebChaot is currently offline  WebChaot
Messages: 52
Registered: September 2006
Location: Austria, Vienna
Member
Hi all!

I needed to implement a function to get a file list of a specific path to FtpClient. Therefore i copied the Load-Function - with different Parameteres it returns a List of Files:


String FtpClient::List(const char *path, Gate1<String> progress) {
LLOGBLOCK("FtpClient::List");
if(!CheckOpen())
return String::GetVoid();
netbuf *ftpdata;
LLOG("FtpAccess(" << path << ")");
if(progress(NFormat(t_("Reading file '%s'"), path))) {
error = t_("aborted");
return String::GetVoid();
}
if(!FtpAccess(path, FTPLIB_DIR, FTPLIB_ASCII, ftpconn, &ftpdata)) {
error = FtpError(ftpconn);
return String::GetVoid();
}
String result;
int p = 0;
for(;;) {
if(progress(result))
break;
byte buffer[1024];
int ndata = FtpRead(buffer, sizeof(buffer), ftpdata);
LLOG("FtpRead -> " << ndata);
if(ndata < 0) {
error = FtpError(ftpdata);
FtpClose(ftpdata);
return String::GetVoid();
}
if(ndata == 0) {
result.Shrink();
break;
}
result.Cat(buffer, ndata);
#ifdef SLOWTRANSFER
int end = GetTickCount() + SLOWTRANSFER;
for(int d; (d = end - GetTickCount()) > 0; Sleep(d))
;
#endif
}
FtpClose(ftpdata);
return result;
}
Re: File List with FtpClient [message #12176 is a reply to message #12175] Mon, 15 October 2007 11:57 Go to previous message
mirek is currently offline  mirek
Messages: 11844
Registered: November 2005
Ultimate Member
WebChaot wrote on Mon, 15 October 2007 05:05

Hi all!

I needed to implement a function to get a file list of a specific path to FtpClient. Therefore i copied the Load-Function - with different Parameteres it returns a List of Files:


String FtpClient::List(const char *path, Gate1<String> progress) {
LLOGBLOCK("FtpClient::List");
if(!CheckOpen())
return String::GetVoid();
netbuf *ftpdata;
LLOG("FtpAccess(" << path << ")");
if(progress(NFormat(t_("Reading file '%s'"), path))) {
error = t_("aborted");
return String::GetVoid();
}
if(!FtpAccess(path, FTPLIB_DIR, FTPLIB_ASCII, ftpconn, &ftpdata)) {
error = FtpError(ftpconn);
return String::GetVoid();
}
String result;
int p = 0;
for(;;) {
if(progress(result))
break;
byte buffer[1024];
int ndata = FtpRead(buffer, sizeof(buffer), ftpdata);
LLOG("FtpRead -> " << ndata);
if(ndata < 0) {
error = FtpError(ftpdata);
FtpClose(ftpdata);
return String::GetVoid();
}
if(ndata == 0) {
result.Shrink();
break;
}
result.Cat(buffer, ndata);
#ifdef SLOWTRANSFER
int end = GetTickCount() + SLOWTRANSFER;
for(int d; (d = end - GetTickCount()) > 0; Sleep(d))
;
#endif
}
FtpClose(ftpdata);
return result;
}


Thank you, patch applied. Welcome to U++ contributors list.

I guess, in future, we should try to make another higher-level function that would provide the structured information instead of text (basically, to parse what you get here...)

Mirek
Previous Topic: Trouble with pointers.
Next Topic: Try / catch
Goto Forum:
  


Current Time: Thu Apr 25 11:47:58 CEST 2019

Total time taken to generate the page: 0.00525 seconds