Download a file from an FTP server

Started by
14 comments, last by .chicken 9 years, 6 months ago

Hmm as I mentioned in the first post, the error I get is from "InternetGetLastResponseInfo" is 2.

aa893a9357d0c5819bd476c6861669e3.png

According to msdn this is the "File Not Found" error. What I'm trying to do, is simply download all files from the server, which match a certain filename-pattern. But right now, I can't even download any file.

Advertisement


I also changed every "\" to "/".

Are you sure your filepath strings are correct? You shouldn't be using single backslashes (as mentioned) as that's an escape.

Have you tried hardcoding both source and destination strings? e.g., from: "remote-server\\dirXYZ\\file.zip" to "c:\\existing-directory\\saveFile.zip" ?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I still think that the error is caused by an invalid local path, not the ftp aspect (assuming that you have the correct port).

Remember that if you define string literals in code, you have to escape the backslashes; but if you take them in from the command line, escaping is not required.

Some old libraries may not recognize forward slashes as directory separators, so for safety, you should use backslashes anyway.

If you're on Windows 7 or later, your Documents folder is, by default, at c:\users\yourusername\documents (replace yourusername with your actual login name). Your user profile should be write-accessible to yourself in any case, so writing the file there should work.

Niko Suni


FtpGetFile(FTPConnect, L"test.zip", L"c:\\users\\johannes\\documents\\test.zip", FALSE,
		FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN | INTERNET_FLAG_RESYNCHRONIZE, 0) == FALSE)

this isn't working.

I tried all possible combinations now..I really don't know what I'm doing wrong


FtpFindFirstFile(FTPConnect, L"*", &dirInfo, INTERNET_FLAG_DONT_CACHE, 0)

This is giving me the same error, and that can't be because of an invalid local path.


	FTPOpen = InternetOpen(LPCTSTR("FileLoader"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
	if (!FTPOpen)
		return false;
	std::cout << "Internet connection opened" << std::endl;

	FTPConnect = InternetConnect(FTPOpen, url, 5553, user, password, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
	if (!FTPConnect)
		return false;
	std::cout << "Connected to FTP server" << std::endl;

	if (FtpSetCurrentDirectory(FTPConnect, folder) == FALSE)
		return false;
	std::cout << "Moved to folder 'HH'" << std::endl;

	return true;

this is returning true, so I don't think the error is here.

The port 5553 is the same port I enter in Filezilla, there I can connect and download just fine.

.

Look up FTP Passive Mode and make sure you understand what happens when you use INTERNET_FLAG_PASSIVE.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Ok, that makes sense, thank you. I changed that to "0" now, but unfortunately it still doesn't work (I turned off the firewall and opened the port in the router). I really thought this app would only take me a few hours...

This topic is closed to new replies.

Advertisement