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 |
WebChaot
Messages: 53 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;
}
|
|
|
Goto Forum:
Current Time: Sat Sep 21 00:43:29 CEST 2024
Total time taken to generate the page: 0.32699 seconds
|