Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved] FTP not working  (Read 4047 times)

0 Members and 1 Guest are viewing this topic.

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
[Solved] FTP not working
« on: December 18, 2014, 03:56:06 pm »
Hello

I just started at my new project and decided to using the SFML library (because that seemed the most attractive to me).

It should connect to a FTP-server, but for some reason it ain't working.

This is my C++ code:
#include <iostream>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <SFML/Network/Export.hpp>
#include <SFML/Network/TcpSocket.hpp>
#include <SFML/Network/Ftp.hpp>

using namespace std;
int main() {
sf::Ftp ftp;
ftp.connect("ftp://myWebsite.com", 21, sf::seconds(120));
sf::Ftp::Response answer = ftp.login("myUsername", "myPassword");
if (answer.isOk()) {
cout<<"FTP worked!"<<endl;
cout<<"Answer received: " << answer.getMessage() << " & " << answer.getStatus() <<endl;
} else if (!answer.isOk()) {
cout<<"Answer not received: " << answer.getMessage() << " & " << answer.getStatus() <<endl;
} else {
cout<<"Unknown error occured!"<<endl;
}
}
 

I'm sure the name of the server, username, and password is right.

This is my G++ input:
(click to show/hide)

Output of program:
(click to show/hide)

Someone able to help?

Found the answer: http://en.sfml-dev.org/forums/index.php?topic=17019.msg122359#msg122359

Thanks for reading,
Niely
« Last Edit: December 20, 2014, 08:37:37 pm by Niely »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: FTP not working
« Reply #1 on: December 18, 2014, 04:44:47 pm »
1002 corresponds to the ConnectionClosed enumeration value according to the documentation. Find out why the server is actively closing the connection, and it will help you solve your problem.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: FTP not working
« Reply #2 on: December 18, 2014, 07:27:12 pm »
But I really don't have a clue why it does that, if I connect to the FTP-server using the File Explorer it works like a charm.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: FTP not working
« Reply #3 on: December 18, 2014, 07:28:58 pm »
Maybe start by checking the servers log file(s) for clues...

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: FTP not working
« Reply #4 on: December 18, 2014, 07:37:10 pm »
It doesn't have a log file I guess, just a basic 000webhost FTP-server.

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: FTP not working
« Reply #5 on: December 18, 2014, 08:23:52 pm »
Found the answer!

I had to change ftp://myWebsite.com to myWebsite.com

So the code of that line is:
ftp.connect("myWebsite.com", 21, sf::seconds(120));

Works like a charm! Can upload and download files now.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: FTP not working
« Reply #6 on: December 18, 2014, 08:53:45 pm »
Then this must be a bug. Even the official documentation has "ftp://" in the code example.
Laurent Gomila - SFML developer

Niely

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: FTP not working
« Reply #7 on: December 19, 2014, 02:10:48 pm »
Could be.
However, if I look at my 000webhost information panel it also says the official FTP-server is myWebsite.com and not ftp://myWebsite.com. Still, I have to use the FTP:// in my browser etc. ;)

Anyway, it works like a charm. :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10976
    • View Profile
    • development blog
    • Email
Re: FTP not working
« Reply #8 on: December 20, 2014, 12:36:05 pm »
Then this must be a bug. Even the official documentation has "ftp://" in the code example.
Is it though? I'd rather say the documentation contains wrong example code.
The sf::Ftp::connect function takes an sf::IpAddress as argument. And as far as I can see, the constructor of sf::IpAddress doesn't take a string with a specific protocol type.

Running the example from the doc with ftp:// doesn't work, same goes for the example shipped with the source code.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: FTP not working
« Reply #9 on: December 20, 2014, 01:12:18 pm »
It should work. If it doesn't support "ftp://", then we should remove it internally before constructing the IpAddress.
Laurent Gomila - SFML developer

 

anything