Advertisement
Guest User

Einfacher FTP Upload

a guest
Apr 8th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <string>
  3. #include <windows.h>
  4. #include <wininet.h>
  5. #include <iostream>
  6. #pragma comment(lib, "Wininet")
  7.  
  8. using namespace std;
  9.  
  10. void ftpupload(wstring &ip, wstring &user, wstring &pass, wstring &file_local, wstring &file_remote)
  11. {
  12.     HINTERNET hConnection;
  13.     HINTERNET hFtpSes;
  14.     hConnection = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
  15.  
  16.     if (hConnection == NULL) {
  17.         cout << GetLastError();
  18.     }
  19.     else {
  20.         hFtpSes = InternetConnect(hConnection, ip.c_str(), INTERNET_DEFAULT_FTP_PORT, user.c_str(), pass.c_str(), INTERNET_SERVICE_FTP, 0, 0);
  21.         if (hFtpSes == NULL) {
  22.             cout << GetLastError();
  23.         }
  24.         else {
  25.             if (!FtpPutFile(hFtpSes, file_local.c_str(), file_remote.c_str(), FTP_TRANSFER_TYPE_BINARY, 0)) {
  26.                 cout << GetLastError();
  27.             }
  28.         }
  29.     }
  30. }
  31.  
  32. int main()
  33. {
  34.     wstring ip(L"127.0.0.1");
  35.     wstring user(L"admin");
  36.     wstring pass(L"passwort");
  37.     wstring file_local(L"C:/lokaledatei.txt");
  38.     wstring file_remote(L"/pfadmussexistieren/aufmserver.txt");
  39.     ftpupload(ip, user, pass, file_local, file_remote);
  40.  
  41.     cin.get();
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement