Skip to content

Commit

Permalink
#1 Changed Status code check for FTP Servers not answering with a spa…
Browse files Browse the repository at this point in the history
…ce after the status code
  • Loading branch information
virtualmarc committed Feb 11, 2020
1 parent 1d237f8 commit 13ffb1d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 0.4.0

-
- Fixed Issue #1 (FTP Servers not sending a space after the status code)

## 0.3.0

Expand Down
8 changes: 4 additions & 4 deletions lib/src/commands/directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ class FTPDirectory {

String sResponse = _socket.readResponse();

return sResponse.startsWith('257 ');
return sResponse.startsWith('257');
}

bool deleteDirectory(String sName) {
_socket.sendCommand('RMD $sName');

String sResponse = _socket.readResponse();

return sResponse.startsWith('250 ');
return sResponse.startsWith('250');
}

bool changeDirectory(String sName) {
_socket.sendCommand('CWD $sName');

String sResponse = _socket.readResponse();

return sResponse.startsWith('250 ');
return sResponse.startsWith('250');
}

String currentDirectory() {
_socket.sendCommand('PWD');

String sResponse = _socket.readResponse();
if (!sResponse.startsWith('257 ')) {
if (!sResponse.startsWith('257')) {
throw FTPException('Failed to get current working directory', sResponse);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/commands/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class FTPFile {
_socket.sendCommand('RNFR $sOldName');

String sResponse = _socket.readResponse();
if (!sResponse.startsWith('350 ')) {
if (!sResponse.startsWith('350')) {
return false;
}

_socket.sendCommand('RNTO $sNewName');

sResponse = _socket.readResponse();
if (!sResponse.startsWith('250 ')) {
if (!sResponse.startsWith('250')) {
return false;
}

Expand All @@ -27,6 +27,6 @@ class FTPFile {
_socket.sendCommand('DELE $sFilename');

String sResponse = _socket.readResponse();
return sResponse.startsWith('250 ');
return sResponse.startsWith('250');
}
}
4 changes: 2 additions & 2 deletions lib/src/commands/filedownload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class FileDownload {
_socket.sendCommand('PASV');

String sResponse = _socket.readResponse();
if (!sResponse.startsWith('227 ')) {
if (!sResponse.startsWith('227')) {
throw FTPException('Could not start Passive Mode', sResponse);
}

int iPort = TransferUtil.parsePort(sResponse);

_socket.sendCommand('RETR $sRemoteName');
sResponse = _socket.readResponse(true);
if (sResponse.startsWith('550 ')) {
if (sResponse.startsWith('550')) {
throw FTPException('Remote File $sRemoteName does not exist!', sResponse);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/commands/fileupload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FileUpload {
_socket.sendCommand('PASV');

String sResponse = _socket.readResponse();
if (!sResponse.startsWith('227 ')) {
if (!sResponse.startsWith('227')) {
throw FTPException('Could not start Passive Mode', sResponse);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/ftpsocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ class FTPSocket {

// Wait for Connect
String sResponse = readResponse();
if (!sResponse.startsWith('220 ')) {
if (!sResponse.startsWith('220')) {
throw FTPException('Unknown response from FTP server', sResponse);
}

// Send Username
sendCommand('USER $user');

sResponse = readResponse();
if (!sResponse.startsWith('331 ')) {
if (!sResponse.startsWith('331')) {
throw FTPException('Wrong username $user', sResponse);
}

// Send Password
sendCommand('PASS $pass');

sResponse = readResponse();
if (!sResponse.startsWith('230 ')) {
if (!sResponse.startsWith('230')) {
throw FTPException('Wrong password', sResponse);
}

Expand Down

0 comments on commit 13ffb1d

Please sign in to comment.