SFML community forums
Help => Network => Topic started by: Sam42 on February 23, 2011, 11:31:24 pm
-
I'm attempting to set up a simple program to grab a few files from an ftp server, and so i've been following the documentation online. At the moment the program is very short, and looks like this:
#include <SFML/Network.hpp>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
// Create a new FTP client
sf::Ftp ftp;
// Connect to the server
sf::Ftp::Response response = ftp.Connect("thesiteaddress");
if (response.IsOk())
cout << "Connected" << std::endl;
// Log in
response = ftp.Login("username", "password");
if (response.IsOk())
cout << "Logged in" << std::endl;
// Print the working directory
sf::Ftp::DirectoryResponse directory = ftp.GetWorkingDirectory();
if (directory.IsOk())
std::cout << "Working directory: " << directory.GetDirectory() << std::endl;
// Download a file to this new directory
response = ftp.Download("blah.txt", "file", sf::Ftp::Ascii);
if (response.IsOk())
{
cout << "File Downloaded" << endl;
}
else
{
cout << response.GetStatus() << endl;
}
ftp.Disconnect();
return EXIT_SUCCESS;
}
Where the site address/username/password are replaced with actual values.
This code results in the following output when compiled and run:
Connected
Logged in
Working directory: /
1001
There is a long wait between working directory, and GetStatus() returning 1001. I've noticed that using something like filezilla i'm unable to get this ftp server to work unless I set it to "active" under Transfer mode.
Any suggestions on what to do, or indeed, pointing out any glaring errors in the code would be greatly appreciated!
-
sf::Ftp always transfers in passive mode, that why it fails if your server doesn't support it.
-
That would explain it! Cheers for the quick reply.
-
How can I upload something to a FTP, from another website without downloading it? I have a garrys mod server, but Uploading is a pain in my I have a very slow upload speed. I would rather just be able to have another site download it, then upload it to my ftp for me. Is there any services online that can do that?
______________________________
market samurai (http://www.keywordspy.com/overview/domain.aspx?q=marketsamurai.com) ~ marketsamurai (http://www.keywordspy.com/overview/domain.aspx?q=marketsamurai.com) ~ marketsamurai.com (http://www.keywordspy.com/overview/domain.aspx?q=marketsamurai.com)