C++ 解析C+中的FTP列表应答+;

C++ 解析C+中的FTP列表应答+;,c++,parsing,ftp,libcurl,ls,C++,Parsing,Ftp,Libcurl,Ls,我未能成功解析libCurl FTP清单中的以下回复 ftplister = fopen("ftp-full-list", "wb"); /* b is binary, needed on win32 */ curl = curl_easy_init(); if(curl) { /* Get a file listing from sunet */ curl_easy_setopt(curl, CURLOPT_URL, furl.c_str() ); cur

我未能成功解析libCurl FTP清单中的以下回复

ftplister = fopen("ftp-full-list", "wb"); /* b is binary, needed on win32 */ 

  curl = curl_easy_init();
  if(curl) {
    /* Get a file listing from sunet */ 
    curl_easy_setopt(curl, CURLOPT_URL, furl.c_str() );
    curl_easy_setopt(curl, CURLOPT_USERPWD, usrpwd.c_str());

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_flist);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftplister);

    res = curl_easy_perform(curl);
    /* Check for errors */ 
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }

  fclose(ftplister); /* close the local file */   
}
写列表是

size_t  semperCloudBackup::write_flist(void *ptr, size_t size, size_t nmemb, void *stream)
{
   FILE *writehere = (FILE *)stream;
  return fwrite(ptr, size, nmemb, writehere);
}
给我一个如下所示的输出

03-26-07  05:23AM       <DIR>          html
03-26-07  04:27AM       <DIR>          laptop
03-26-07  03:16AM       <DIR>          images
03-27-07  11:00PM                 6397 index.html
03-26-07  03:45AM                10186 index1.html
03-26-07 05:23上午html
03-26-07 04:27AM笔记本电脑
03-26-07 03:16上午图片
03-27-07 11:00PM 6397 index.html
03-26-07 03:45AM 10186 index1.html
我必须 1.查找它是目录还是文件 2.存储文件及其大小(我猜是在数组中),以便对大小进行一些计算。 3.分别存储目录名

任何帮助都将不胜感激,这里的新手。多谢各位

经过大量的搜索,我想我在perl中找到了一些东西,但我想在C中找到它++

#!/usr/bin/perl
use warnings;
use strict;

while(<DATA>) {
    chomp;
    my @elements = split /\s+/, $_;
    if ( $elements[2] eq '<DIR>' ) {
        print "Directory: ",$elements[3], "\n";
    }
    else {
        print "The size of $elements[3] is $elements[2] bytes.\n";
    }
}

__DATA__
03-26-07  05:23AM       <DIR>          html
03-26-07  04:27AM       <DIR>          ibm-laptop
03-26-07  03:16AM       <DIR>          images
03-27-07  11:00PM                 6397 index.html
03-26-07  03:45AM                10186 index1.html
#/usr/bin/perl
使用警告;
严格使用;
while(){
咀嚼;
my@elements=split/\s+/,$;
如果($elements[2]等式“”){
打印“目录:”,$elements[3],“\n”;
}
否则{
打印“$elements[3]的大小为$elements[2]字节。\n”;
}
}
__资料__
03-26-07 05:23上午html
03-26-07 04:27AM ibm笔记本电脑
03-26-07 03:16上午图片
03-27-07 11:00PM 6397 index.html
03-26-07 03:45AM 10186 index1.html
我也发现了这个

为了单独阅读每一行(虽然不是完全有用),我使用了以下方法:

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main() {
      // a string to store line of text
      string textLine;
      // try to open a file
      ifstream ifs("sample_file.txt", ifstream::in);
      if (ifs.good())   { // if opening is successful
            // while file has lines
            while (!ifs.eof()) {
                  // read line of text
                  getline(ifs, textLine);
                  // print it to the console
                  cout << textLine << endl;
            }
            // close the file
            ifs.close();
      } else
            // otherwise print a message
            cout << "ERROR: can't open file." << endl;

      return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main(){
//用于存储文本行的字符串
字符串文本行;
//尝试打开一个文件
ifstream-ifs(“sample_file.txt”,ifstream::in);
if(ifs.good()){//如果打开成功
//而文件有行
而(!ifs.eof()){
//读一行文字
getline(ifs,textLine);
//将其打印到控制台

这提醒我们FTP有多么丑陋:命令的输出在任何方面都没有标准化。根据最初的RFC,服务器可以自由地向您发送它想要的任何类型的响应。我完全理解Daniel,当我搜索相同的内容时,我得到了各种各样的答案并意识到了这个问题。但服务器只发送作为pr的回复ivate FTP服务器。