Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - irrmich

Pages: [1]
1
 ;D okay I've created a PULL REQUEST to do this
I tested it on my machine, it works fine with my real ftp server and on filezilla too :)

2
I come here to ask for extending the current ftp::upload function which only support overwriting remote file, I suggest to replace it.

So the previous function:

Response sf::Ftp::upload        (       const std::string &     localFile,
const std::string &     remotePath,
TransferMode    mode = Binary
)
{
    // Get the contents of the file to send
    std::ifstream file(localFile.c_str(), std::ios_base::binary);
    if (!file)
        return Response(Response::InvalidFile);

    // Extract the filename from the file path
    std::string filename = localFile;
    std::string::size_type pos = filename.find_last_of("/\\");
    if (pos != std::string::npos)
        filename = filename.substr(pos + 1);

    // Make sure the destination path ends with a slash
    std::string path = remotePath;
    if (!path.empty() && (path[path.size() - 1] != '\\') && (path[path.size() - 1] != '/'))
        path += "/";

    // Open a data channel using the given transfer mode
    DataChannel data(*this);
    Response response = data.open(mode);
    if (response.isOk())
    {
        // Tell the server to start the transfer
        response = sendCommand("STOR", path + filename);
        if (response.isOk())
        {
            // Send the file data
            data.send(file);

            // Get the response from the server
            response = getResponse();
        }
    }

    return response;
}
 

should be replaced by:

Response sf::Ftp::upload        (       const std::string &     localFile,
const std::string &     remotePath,
TransferMode    mode = Binary,
bool append = false
)
{
    // Get the contents of the file to send
    std::ifstream file(localFile.c_str(), std::ios_base::binary);
    if (!file)
        return Response(Response::InvalidFile);

    // Extract the filename from the file path
    std::string filename = localFile;
    std::string::size_type pos = filename.find_last_of("/\\");
    if (pos != std::string::npos)
        filename = filename.substr(pos + 1);

    // Make sure the destination path ends with a slash
    std::string path = remotePath;
    if (!path.empty() && (path[path.size() - 1] != '\\') && (path[path.size() - 1] != '/'))
        path += "/";

    // Open a data channel using the given transfer mode
    DataChannel data(*this);
    Response response = data.open(mode);
    if (response.isOk())
    {
        // Tell the server to start the transfer
        if(append)
        {
                response = sendCommand("APPE", path + filename);
         } else
         {
                response = sendCommand("STOR", path + filename)
         }
       
        if (response.isOk())
        {
            // Send the file data
            data.send(file);

            // Get the response from the server
            response = getResponse();
        }
    }

    return response;
}
 

I searched on google, on stackoverflow and i undestood that:
      _wininet does not support ftp append correctly
      _other ftp libs which support this feature are commercial or outdated

SFML network must implement it so that we attire more network programmers to SFML, and it won't affect client codes which use the current implementation of sf::ftp::upload()  8)

Pages: [1]