Suliman
Suliman

Reputation: 1499

How to get list of file on FTP with D?

I need to get list of files on FTP. I wrote next code, but it's crash at startup.

void main()
{
string ftpserver = "myftpserver";
string ftplogin = "username";
string ftppass = "pass";

    auto ftp = FTP(ftpserver);
    ftp.verbose(1);
    ftp.setAuthentication(ftplogin, ftppass);
    ftp.addCommand("LIST");
    ftp.perform();
}

The problem with addCommand, because if remove it App start, show FTP root dir and then exit.

Ok. Command sended but how to get result of it? addCommand have type void.

P.S. And I can't understand why after connecting it's immediately exit?

Upvotes: 1

Views: 198

Answers (3)

Matt Kline
Matt Kline

Reputation: 10487

As others have suggested, LIST is not a valid FTP command. You can find a list of valid commands here.

Also, before calling perform, you should set a callback that receives incoming data with onReceive. That callback can accumulate the results into a string or whatever else you want to do with them.

Upvotes: 0

Kozzi11
Kozzi11

Reputation: 2413

Problem is with ftp.perform, OK not with method itself, because as frasnian said problem is with LIST command. But if you look on documentation to method perform you should see ThrowOnError throwOnError as a first parameter of this method. So you can make it nothrow or put it into try catch block.

But this still doesn`t fix your problem with bad command.

Upvotes: 0

frasnian
frasnian

Reputation: 2003

Try changing addCommand() from "LIST" (not a valid FTP command) to either "LS" or "ls" (they behave differently on some sites).

I'm not sure about all of the D bindings for curl - you can normally get the results of perform() by calling curl_getinfo(). I know D does at least have bindings for these:

CURLcode  curl_easy_perform(CURL *curl);
CURLcode  curl_easy_getinfo(CURL *curl, CURLINFO info,...);

which may be a better alternative, anyway, depending on your needs.

Upvotes: 1

Related Questions