From 13ffb1d74f58afb246f35d2e508cbe22e5accd29 Mon Sep 17 00:00:00 2001 From: virtualmarc Date: Tue, 11 Feb 2020 17:34:07 +0100 Subject: [PATCH] #1 Changed Status code check for FTP Servers not answering with a space after the status code --- CHANGELOG.md | 2 +- lib/src/commands/directory.dart | 8 ++++---- lib/src/commands/file.dart | 6 +++--- lib/src/commands/filedownload.dart | 4 ++-- lib/src/commands/fileupload.dart | 2 +- lib/src/ftpsocket.dart | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2699621..4dd940f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.4.0 -- +- Fixed Issue #1 (FTP Servers not sending a space after the status code) ## 0.3.0 diff --git a/lib/src/commands/directory.dart b/lib/src/commands/directory.dart index a77d8e7..d3e206d 100644 --- a/lib/src/commands/directory.dart +++ b/lib/src/commands/directory.dart @@ -11,7 +11,7 @@ class FTPDirectory { String sResponse = _socket.readResponse(); - return sResponse.startsWith('257 '); + return sResponse.startsWith('257'); } bool deleteDirectory(String sName) { @@ -19,7 +19,7 @@ class FTPDirectory { String sResponse = _socket.readResponse(); - return sResponse.startsWith('250 '); + return sResponse.startsWith('250'); } bool changeDirectory(String sName) { @@ -27,14 +27,14 @@ class FTPDirectory { 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); } diff --git a/lib/src/commands/file.dart b/lib/src/commands/file.dart index 75366c0..06dfd15 100644 --- a/lib/src/commands/file.dart +++ b/lib/src/commands/file.dart @@ -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; } @@ -27,6 +27,6 @@ class FTPFile { _socket.sendCommand('DELE $sFilename'); String sResponse = _socket.readResponse(); - return sResponse.startsWith('250 '); + return sResponse.startsWith('250'); } } diff --git a/lib/src/commands/filedownload.dart b/lib/src/commands/filedownload.dart index 43bec67..d0987b5 100644 --- a/lib/src/commands/filedownload.dart +++ b/lib/src/commands/filedownload.dart @@ -24,7 +24,7 @@ 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); } @@ -32,7 +32,7 @@ class FileDownload { _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); } diff --git a/lib/src/commands/fileupload.dart b/lib/src/commands/fileupload.dart index 4d484f2..a8f223f 100644 --- a/lib/src/commands/fileupload.dart +++ b/lib/src/commands/fileupload.dart @@ -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); } diff --git a/lib/src/ftpsocket.dart b/lib/src/ftpsocket.dart index 05343d1..2f23fe2 100644 --- a/lib/src/ftpsocket.dart +++ b/lib/src/ftpsocket.dart @@ -63,7 +63,7 @@ class FTPSocket { // Wait for Connect String sResponse = readResponse(); - if (!sResponse.startsWith('220 ')) { + if (!sResponse.startsWith('220')) { throw FTPException('Unknown response from FTP server', sResponse); } @@ -71,7 +71,7 @@ class FTPSocket { sendCommand('USER $user'); sResponse = readResponse(); - if (!sResponse.startsWith('331 ')) { + if (!sResponse.startsWith('331')) { throw FTPException('Wrong username $user', sResponse); } @@ -79,7 +79,7 @@ class FTPSocket { sendCommand('PASS $pass'); sResponse = readResponse(); - if (!sResponse.startsWith('230 ')) { + if (!sResponse.startsWith('230')) { throw FTPException('Wrong password', sResponse); }