Advertisement
Guest User

Untitled

a guest
May 19th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include <wininet.h>
  5. #include <string>
  6. #pragma comment (lib, "Wininet.lib")
  7.  
  8. using namespace std;
  9.  
  10. int PobierzPlik(char remoteFile[], char newFile[]){//nazwa na serwerze potem nazwa na dysku
  11.  
  12.  
  13. char ftp[] = "85.17.73.180";
  14.  
  15. char user[] = "admin@testujemyhtml.cba.pl";
  16.  
  17. char password[] = "admin@testujemyhtml.cba.pl";
  18.  
  19. HINTERNET hInternet;
  20.  
  21. HINTERNET hFtpSession;
  22.  
  23. if (InternetAttemptConnect(0) == ERROR_SUCCESS)
  24. {
  25.  
  26. std::cout << "Czekaj..." << endl;
  27. }
  28. else { cout << "Error!(Blad polaczenia?)\n" << endl; return -1; }
  29.  
  30.  
  31. hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
  32.  
  33. if (hInternet != NULL){
  34.  
  35. hFtpSession = InternetConnect(hInternet, ftp, INTERNET_DEFAULT_FTP_PORT, user, password, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
  36.  
  37. if (hFtpSession != NULL){
  38.  
  39. if (FtpGetFile(hFtpSession, remoteFile, newFile, true, FILE_ATTRIBUTE_NORMAL, INTERNET_FLAG_TRANSFER_BINARY, 0)) {
  40.  
  41. InternetCloseHandle(hFtpSession);
  42.  
  43. InternetCloseHandle(hInternet);
  44.  
  45. }
  46. else {
  47. cout << "Error!(Blad polaczenia?)\n" << endl;
  48. return -1;
  49. }
  50.  
  51.  
  52. }
  53. else return -1;
  54.  
  55. }
  56.  
  57. else return -1;
  58.  
  59. cout << "Gotowe!" << endl;
  60.  
  61. return 0;
  62.  
  63. };
  64. int WyslijPlik(){
  65.  
  66. char ftp[] = "85.17.73.180";
  67.  
  68. char user[] = "admin@testujemyhtml.cba.pl";
  69.  
  70. char password[] = "admin@testujemyhtml.cba.pl";
  71.  
  72. char localFile[] = "D:\baza2.txt";
  73.  
  74. char remoteFile[] = "/baza2.txt";
  75. cout << user << endl << password << endl;
  76.  
  77. HINTERNET hInternet;
  78.  
  79. HINTERNET hFtpSession;
  80.  
  81. if (InternetAttemptConnect(0) == ERROR_SUCCESS) cout << "Internet dostepny, wysylanie pliku..\n" << endl;
  82.  
  83. else { cout << "Internet niedostepny.\n" << endl; return -1; }
  84.  
  85.  
  86. hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
  87.  
  88. if (hInternet != NULL){
  89.  
  90. hFtpSession = InternetConnect(hInternet, ftp, INTERNET_DEFAULT_FTP_PORT, user, password, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
  91.  
  92. if (hFtpSession != NULL){
  93.  
  94. if (FtpPutFile(hFtpSession, localFile, remoteFile, FTP_TRANSFER_TYPE_BINARY, 0)){
  95.  
  96. InternetCloseHandle(hFtpSession);
  97.  
  98. InternetCloseHandle(hInternet);
  99.  
  100. }
  101. else {
  102. cout << "Blad podczas wysylania pliu." << endl;
  103. return -1;
  104. }
  105.  
  106.  
  107. }
  108.  
  109. else return -1;
  110.  
  111.  
  112. }
  113.  
  114. else return -1;
  115.  
  116. cout << "Wyslano Plik.\n" << endl;
  117.  
  118. return 0;
  119.  
  120. };
  121.  
  122. int main(){
  123. //WyslijPlik();
  124. PobierzPlik("//bank//baza.txt", "D://baza.txt");
  125.  
  126.  
  127. system("pause");
  128.  
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement