SFML community forums

Help => Network => Topic started by: Niely on January 03, 2015, 10:42:46 pm

Title: FTP Status 1002
Post by: Niely on January 03, 2015, 10:42:46 pm
Hello

I get a status 1002 when trying my application.
It says it means 'ConnectionClosed', what is the difference with that regarding 'ConnectionFailed'?

And, what exactly does it means? And, how to fix it?
I've already called ftp.keepAlive() before the login() function, but that didn't worked.
Title: Re: FTP Status 1002
Post by: Ixrec on January 03, 2015, 11:03:38 pm
This is purely a question about the FTP protocol.  Unless you have some reason to believe SFML is the root cause of the problem, you would probably be better off googling "FTP 1002".

For example, https://stackoverflow.com/questions/26647423/nsurlerrordomain-error-code-1002-description and http://dev.error1002.com/faq_connect.php#1002 suggest that a bad URL is one possible cause.
Title: Re: FTP Status 1002
Post by: Laurent on January 03, 2015, 11:36:03 pm
FTP codes >= 1000 are specific to SFML, the FTP RFC only defines codes up to 5xx (similarly to HTTP, the major digit is the status "category").

So no, this is not purely a FTP issue, and no, Googling for error 1002 in this case would not help much ;)
Title: Re: FTP Status 1002
Post by: Ixrec on January 03, 2015, 11:45:35 pm
Oh...well, I guess it would be nice if the tutorial or documentation mentioned this somewhere.
Title: Re: FTP Status 1002
Post by: Laurent on January 03, 2015, 11:56:04 pm
https://github.com/SFML/SFML/pull/763 ;)
Title: Re: FTP Status 1002
Post by: Niely on January 04, 2015, 11:30:55 am
Okay, connection with server closed. So, that means that it suddenly closed? But I used 'keepAlive()'.
Could it also mean the specified server doesn't exist?
Title: Re: FTP Status 1002
Post by: Laurent on January 04, 2015, 12:14:15 pm
Quote
Could it also mean the specified server doesn't exist?
No, you would get a ConnectionFailed error in this case. ConnectionClosed means that you were connected to the server, but the connection suddenly broke.

Quote
But I used 'keepAlive()'.
How do you use it?
Title: Re: FTP Status 1002
Post by: Niely on January 04, 2015, 12:57:52 pm
Here is another code example where it also doesn't work:

#include <iostream>
#include <string>

#include <SFML/Network.hpp>

using namespace std;
int main() {
sf::Ftp ftp;
sf::Ftp::Response response;
string server, username, password;
int port;


cin >> server;
cin >> port;

ftp.connect(server, port);
ftp.keepAlive();

cin >> username;
cin >> password;

response = ftp.login(username, password);

if (response.isOk()) {
        cout<< "Ok" <<endl;
} else if (!response.isOk()) {
        cout << "Not ok; Status " << response.getStatus() <<endl;
} else {
        cout<< "Error" <<endl;
}
}
Title: Re: FTP Status 1002
Post by: Laurent on January 04, 2015, 01:57:16 pm
keepAlive() must be called periodically, what it does is only to send a no-op to the server to signal that you're still there.

Does it work if you hard-code the login and password, so that there's no delay between the commands?
Title: Re: FTP Status 1002
Post by: Niely on January 04, 2015, 06:11:41 pm
^No,

#include <iostream>
#include <string>

#include <SFML/Network.hpp>

using namespace std;
int main() {
sf::Ftp ftp;
sf::Ftp::Response response;
/*string server, username, password;
int port;


cin >> server;
cin >> port;
*/

ftp.connect("ftp://server.cf");
/*
cin >> username;
cin >> password;
*/

response = ftp.login("myUser", "MyPass");

if (response.isOk()) {
        cout<< "Ok" <<endl;
} else if (!response.isOk()) {
        cout << "Not ok; Status " << response.getStatus() <<endl;
} else {
        cout<< "Error" <<endl;
}
}
 

FTP through browser with exact same authentication does work though.
Title: Re: FTP Status 1002
Post by: Laurent on January 04, 2015, 07:23:10 pm
Can you print the body and status of the response to the connect call?
Title: Re: FTP Status 1002
Post by: Jesper Juhl on January 04, 2015, 07:34:11 pm
If it was me debugging this I'd start by fireing up Wireshark (https://www.wireshark.org) and capture a working session from a commandline ftp client and then a trace with my application and then compare what happens on the wire in the two cases.
Title: Re: FTP Status 1002
Post by: Niely on January 04, 2015, 07:54:53 pm
It says that status is 1002, and getBody isn't a function of sf::Ftp::Response.
I think getBody() is for HTTP.

What weird is, I tried filtering port 21 in Wireshark but it captured nothing when I ran my application. I closed my browser and tried that application as well; in Linux' process manager network also was 0 (didn't react).

So my application actually isn't sending a request...
Title: Re: FTP Status 1002
Post by: Laurent on January 04, 2015, 08:33:12 pm
Quote
It says that status is 1002
So it's happening on connect(), not on login()?

Quote
getBody isn't a function of sf::Ftp::Response.
I think getBody() is for HTTP.
Well, the content of the response (getMessage).
Title: AW: Re: FTP Status 1002
Post by: eXpl0it3r on January 04, 2015, 08:38:47 pm
What weird is, I tried filtering port 21 in Wireshark but it captured nothing when I ran my application. I closed my browser and tried that application as well; in Linux' process manager network also was 0 (didn't react).

So my application actually isn't sending a request...
Do you use a local FTP server?
Did you pick the correct interface?
What if you just use "ftp" as filter?
Title: Re: FTP Status 1002
Post by: Niely on January 04, 2015, 09:29:35 pm
getMessage is blanco. The response of connect is 1001, login 1002.

Ouput:
Quote
Connecting Not ok; Status 1001
Logging in Not ok; Status 1002

Code:
#include <iostream>
#include <string>

#include <SFML/Network.hpp>

using namespace std;
int main() {
sf::Ftp ftp;
sf::Ftp::Response response, response2;
/*string server, username, password;
int port;


cin >> server;
cin >> port;
*/

response = ftp.connect("ftp://server.cf");
/*
cin >> username;
cin >> password;
*/

response2 = ftp.login("myUser", "MyPass");

if (response.isOk()) {
        cout<< "Ok" <<endl;
} else if (!response.isOk()) {
        cout << "Connecting Not ok; Status " << response.getStatus()<< " " << response.getMessage()<<endl;
} else {
        cout<< "Error" <<endl;
}

if (response2.isOk()) {
        cout<< "Ok" <<endl;
} else if (!response2.isOk()) {
        cout << "Logging in Not ok; Status " << response2.getStatus()<< " " << response2.getMessage()<<endl;
} else {
        cout<< "Error" <<endl;
}
}

I used interface Wlan0, also tried FTP filter; the same result.
Not using local ftp-server, but a normal over-internet one.
Title: Re: FTP Status 1002
Post by: Demir on January 04, 2015, 09:33:09 pm
I'm not good at networking.
I try to follow what's new in the current version of SFML.


I worked with sf::Ftp a bit.

As I can see getaddrinfo() function doesn't like ftp:// prefix.
Title: Re: FTP Status 1002
Post by: Niely on January 04, 2015, 09:58:06 pm
What exactly do you mean?
Title: Re: FTP Status 1002
Post by: eXpl0it3r on January 04, 2015, 10:05:53 pm
Just use server.cf instead of ftp://server.cf.
Title: Re: FTP Status 1002
Post by: Laurent on January 04, 2015, 10:56:41 pm
Quote
The response of connect is 1001
So... that is the problem. You cannot connect to the server at all, and yes this is probably because of the "ftp://" prefix.

That's why checking every possible call that reports a status is important: otherwise you may look for a bug at the wrong place.
Title: Re: FTP Status 1002
Post by: Niely on January 06, 2015, 08:51:37 pm
^It's indeed connecting now. :)
Thanks a lot all!

However, I still have to change a few things to make it do more what I want.