///////////////////////////////////////////////////////
| 336 | |
| 337 | //////////////////////////////////////////////////////////// |
| 338 | Ftp::Response Ftp::upload(const std::filesystem::path& localFile, |
| 339 | const std::filesystem::path& remotePath, |
| 340 | TransferMode mode, |
| 341 | bool append) |
| 342 | { |
| 343 | // Get the contents of the file to send |
| 344 | std::ifstream file(localFile, std::ios_base::binary); |
| 345 | if (!file) |
| 346 | return Response(Response::Status::InvalidFile); |
| 347 | |
| 348 | // Open a data channel using the given transfer mode |
| 349 | DataChannel data(*this); |
| 350 | Response response = data.open(mode); |
| 351 | if (response.isOk()) |
| 352 | { |
| 353 | // Tell the server to start the transfer |
| 354 | response = sendCommand(append ? "APPE" : "STOR", (remotePath / localFile.filename()).string()); |
| 355 | if (response.isOk()) |
| 356 | { |
| 357 | // Send the file data |
| 358 | data.send(file); |
| 359 | |
| 360 | // Get the response from the server |
| 361 | response = getResponse(); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | return response; |
| 366 | } |
| 367 | |
| 368 | |
| 369 | //////////////////////////////////////////////////////////// |