-
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.
-
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.
-
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 ;)
-
Oh...well, I guess it would be nice if the tutorial or documentation mentioned this somewhere.
-
https://github.com/SFML/SFML/pull/763 ;)
-
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?
-
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.
But I used 'keepAlive()'.
How do you use it?
-
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;
}
}
-
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?
-
^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.
-
Can you print the body and status of the response to the connect call?
-
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.
-
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...
-
It says that status is 1002
So it's happening on connect(), not on login()?
getBody isn't a function of sf::Ftp::Response.
I think getBody() is for HTTP.
Well, the content of the response (getMessage).
-
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?
-
getMessage is blanco. The response of connect is 1001, login 1002.
Ouput:
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.
-
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.
-
What exactly do you mean?
-
Just use server.cf instead of ftp://server.cf.
-
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.
-
^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.