Still Having Isssues

Hi Guys!

I am still having trouble with the following code. I need to replace the IP address to contain the value (127.0.0.1). I have tried many things without success.

std::string ip; -- Contains (127.0.0.1)

Thanks for taking a look at this post!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	std::ifstream f("c:\\Windows\\Temp\\Test.txt");
				std::string ip;

				for (int i = 1; i <= 15; i++)
					std::getline(f, ip);

				std::cout << ip << '\n';



			HINTERNET hInternet = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
				HINTERNET hFtpSession = InternetConnectA(hInternet, ip.c_str(),
					INTERNET_DEFAULT_FTP_PORT, "test", "test",
					INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
				FtpPutFileA(hFtpSession, "C:/screen.jpeg", "/testing1.jpeg", FTP_TRANSFER_TYPE_BINARY, 0);
				std::cout << "\nFile Uploaded!\n";
				InternetCloseHandle(hFtpSession);
				InternetCloseHandle(hInternet);
When asking somebody a question, never say "I'm having trouble" or "it's not working". Be specific. What exactly is the problem you're seeing? The more follow-up questions we need to ask the longer it's going to take before you arrive at a solution.
Im sorry but I thought this was a beginners forum...
https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetopena
https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetconnecta
https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-ftpputfilea
All have

Returns something if successful, or something else otherwise.
To get a specific error message, call GetLastError.

So before you start posting "it doesn't work", you should plaster your code with all the error checking you can muster to
a) find out which function is failing
b) find out the reason for it failing

Even assuming that you have an FTP server configured on your local machine, it would be an incredibly dumb move to give something that powerful which such inherently weak security unfettered access to C:\



Im sorry but I thought this was a beginners forum...
I was not aware I had the ability to read the minds of beginner programmers. Let me give that a try.

...

Nope. Still don't know what your problem is.
Im sorry but I thought this was a beginners forum...

well, yes. But most beginners here are asking 'how you loop to print every other number' not 'how to do networking'.
Even so, its fine, but we still need to know as much as you can feed us about the problem. Networking is not just code, unlike that print loop; it is a combination of code and your computer setup. If for example you try to open an ip address that cannot be resolved from your computer, no amount of debugging or coding is going to fix that.

That said,
you get 14 strings, 14 full lines of text, in a loop, discarding the first 13 of them:
1
2
3
4
5
6
std::string ip;

				for (int i = 1; i <= 15; i++)
					std::getline(f, ip); 

				std::cout << ip << '\n';



that may be correct if the file has 13 lines of junk that you do not want. but you need to tell us that.
what does the cout provide? Is it the correct value there? I recommend splitting the file reader and the networking stuff apart, but for now lets get it working.

if you want to check the IP address, you can cheat and just say
string cmd = "ping " + ip;
system(cmd);
Last edited on
Topic archived. No new replies allowed.