Im going to try and rephrase my question.

Hii Guys!!

I have posted previously about my predicament and was told by other members to be more specific, so here goes!

I have the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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:/Test.txt", "/Testing.txt", FTP_TRANSFER_TYPE_BINARY, 0);
std::cout << "\nFile Uploaded!\n";
InternetCloseHandle(hFtpSession);
InternetCloseHandle(hInternet);


Now, "ip.c_str()" contains "127.0.0.1" from line 15 of "c:\\Windows\\Temp\\Test.txt". When I inclued "ip.c_str()" into the following code, it dosnt upload the file to the FTP server.

-----
HINTERNET hFtpSession = InternetConnectA(hInternet, ip.c_str(),
INTERNET_DEFAULT_FTP_PORT, "test", "test",
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
-----

If I was to replace "ip.c_str()" with (L"127.0.0.1") it will upload the text file successfully.

Also, if I were to have (char str2[] = "127.0.0.1";) and replace the "ip.c_str()" with "str2" it does the same thing and the file does not save.

Many thanks for taking the time to read this and have a wonderful day!!
Last edited on
You haven't said anything new at all.
https://www.cplusplus.com/forum/beginner/270704/

You have 3 complex functions that return a whole host of different error conditions and you're not telling us ANY of that information.
Starting a new thread for the same issue is a great way to ensure nobody sees the new information.

If I was to replace "ip.c_str()" with (L"127.0.0.1") it will upload the text file successfully.

Also, if I were to have (char str2[] = "127.0.0.1";) and replace the "ip.c_str()" with "str2" it does the same thing and the file does not save.
It sounds like there are extraneous characters in the string.

Like salem c said, your thoubleshooting is in too broad strokes. This is like trying to figure out what's wrong with a car by sitting in it blindfolded and pushing on the gas pedal for half an hour, and seeing if when you get back out you've arrived at your destination.
Do error handling. Check the return values from the functions. Check the error states. Networks are complex systems. There are many things that can go wrong when doing something as complex as an FTP upload.
> If I was to replace "ip.c_str()" with (L"127.0.0.1") it will upload the text file successfully.
Mmmm.

> InternetConnectA
https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetconnecta
vs
https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetconnectw

There's something wacky with your build if passing a wide string to an 'A' function makes it work.

Or maybe your wide string is just seen in the ANSI function as being the same as "". You could have just passed in L"banana.republic" and it would still work.

How many warnings are you getting when you compile the code that you're also not telling us.
Check the return code of each call and any auxiliary variables it sets (like errno). Read the documentation of each call to see what it returns for an error.

The calls will tell you what you did wrong. You just need to ask them.

This may seem tedious but you need to get used to it if you plan on going into programming. About 75%-90% of "real world" code is error checking and recovery.
does it work with this?

wchar_t str2[] = "127.0.0.1" ?

Topic archived. No new replies allowed.