swiftsocket/SwiftSocket

451 The parameter is incorrect

Nathipha opened this issue · 1 comments

I successfully opened a socket and got the "220 Service ready for new user" response from the server but if I then try to enter the username and password, the response is always:

451 The parameter is incorrect

Code:

switch client.send(string: "USER myuser\n") {
    case .success:
        if let data = client.read(1024*10, timeout: 10) {
            if let response = String(bytes: data, encoding: .utf8) {
                print("user answer: \(response)")
            } else {
                print("user response nil")
            }
        } else {
            print("user read data nil")
        }
    case .failure(let error):
        print("user Error: \(error)\n\(error.localizedDescription)")
}

If I use "USER myuser" in ftp command line (in Windows), I get the right answer, so I know that the server's responding the right way.

Am I missing anything?

Found the problem:

The requests are sent using binary mode, so instead of "USER myuser\n" you have to use "USER myuser\r\n"!