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()