R
R
Riddik2015-10-03 14:32:08
FTP
Riddik, 2015-10-03 14:32:08

How to upload a file to an FTP server from a C++ (win) program?

Hello.
There is a win32 application, there is an ftp server address with a login and password.
How can I upload a file from the user's machine to this ftp server from this application?
How to do this in the easiest way and with as few extra libs as possible? Empty to a file on the user's machine may contain Cyrillic (i.e. do you need Unicode?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Riddik, 2015-10-03
@TrueRiddik

Found an article on MSDN that helped me do the right thing.
Article: https://msdn.microsoft.com/en-us/library/windows/d...

void UploadFile(LPCTSTR lpszLocalFile)
{
  HINTERNET hInternet = InternetOpen(L"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, INTERNET_FLAG_ASYNC);

  HINTERNET hConnect = InternetConnect(hInternet , L"xxxxxxxxxxx", INTERNET_DEFAULT_FTP_PORT, L"xxxxxxxxxxxx", L"xxxxxxx", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);

  //
  BOOL result = FtpPutFile(hConnect, lpszLocalFile, L"xxxxxxxxxxxxxxxx", FTP_TRANSFER_TYPE_BINARY, 0);

  ...
  
  //
  InternetCloseHandle(hConnect);
  InternetCloseHandle(hInternet);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question