Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: abort upload once an error occures #11

Merged
merged 2 commits into from
Apr 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions src/Commands/STOR.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@
class STOR : public FTPCommandTransfer
{
public:
explicit STOR(WiFiClient * const Client, FTPFilesystem * const Filesystem, IPAddress * DataAddress, int * DataPort)
explicit STOR(WiFiClient *const Client, FTPFilesystem *const Filesystem, IPAddress *DataAddress, int *DataPort)
: FTPCommandTransfer("STOR", 1, Client, Filesystem, DataAddress, DataPort)
{}

void run(FTPPath & WorkDirectory, const std::vector<String> & Line) override
{
if(trasferInProgress())
}

void run(FTPPath &WorkDirectory, const std::vector<String> &Line) override
{
if (trasferInProgress())
{
return;
}
if(!ConnectDataConnection())
if (!ConnectDataConnection())
{
return;
}
String path = WorkDirectory.getFilePath(Line[1]);
_file = _Filesystem->open(path, "w");
if(!_file)
_ftpFsFilePath = WorkDirectory.getFilePath(Line[1]);
_file = _Filesystem->open(_ftpFsFilePath, "w");
if (!_file)
{
SendResponse(451, "Can't open/create " + _ftpFsFilePath);
CloseDataConnection();
SendResponse(451, "Can't open/create " + path);
return;
}
workOnData();
Expand All @@ -39,17 +40,28 @@ class STOR : public FTPCommandTransfer
{
uint8_t buffer[FTP_BUF_SIZE];
int nb = data_read(buffer, FTP_BUF_SIZE);
if(nb > 0)
if (nb > 0)
{
_file.write(buffer, nb);
const auto wb = _file.write(buffer, nb);
if (wb != nb)
{
_file.close();
this->_Filesystem->remove(_ftpFsFilePath.c_str());

SendResponse(552, "Error occured while STORing");
CloseDataConnection();
}

return;
}
CloseDataConnection();

SendResponse(226, "File successfully transferred");
CloseDataConnection();
_file.close();
}

private:
String _ftpFsFilePath;
};

#endif