Beispiel #1
0
ftp_client::response
    ftp_client::get(const char* remotefile, stream& ostream) const
{
    response rsp;

    if (!ostream.writable())
    {
        rsp.status[0] = 0;
        rsp.detail    = "Invalid output stream.";
        return rsp;
    }

    rsp = size(remotefile);
    if (rsp.status[0] != '2')
        return rsp;

    unsigned long total = atol(rsp.detail.c_str());

    tcp_stream tcp = impl_->create_tcp_stream_from_pasv();
    if (!tcp.readable())
    {
        rsp.status[0] = 0;
        rsp.detail    = "Create retr data connection failed.";
        return rsp;
    }

    rsp = sendcmd("RETR %s", remotefile);
    if (rsp.status[0] != '1')
        return rsp;

    unsigned long getted = ostream.plunder(tcp);
    if (getted != total)
    {
        rsp.status[0] = 0;
        rsp.detail    = stralgo::format("getted/total: %ld/%ld", getted, total);
        return rsp;
    }

    return impl_->get_response();
}
Beispiel #2
0
ftp_client::response ftp_client::list(const char* path, stream& ostream) const
{
    response rsp;

    tcp_stream tcp = impl_->create_tcp_stream_from_pasv();
    if (!tcp.readable())
    {
        rsp.status[0] = 0;
        rsp.detail    = "Create list data connection failed.";
        return rsp;
    }

    if (path)
        rsp = sendcmd("LIST %s", path);
    else
        rsp = sendcmd("LIST");

    if (rsp.status[0] != '1')
        return rsp;

    ostream.plunder(tcp);

    return impl_->get_response();
}