Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <Windows.h>
- #include <wininet.h>
- #include <string>
- #pragma comment (lib, "Wininet.lib")
- using namespace std;
- int PobierzPlik(char remoteFile[], char newFile[]){//nazwa na serwerze potem nazwa na dysku
- char ftp[] = "85.17.73.180";
- char user[] = "admin@testujemyhtml.cba.pl";
- char password[] = "admin@testujemyhtml.cba.pl";
- HINTERNET hInternet;
- HINTERNET hFtpSession;
- if (InternetAttemptConnect(0) == ERROR_SUCCESS)
- {
- std::cout << "Czekaj..." << endl;
- }
- else { cout << "Error!(Blad polaczenia?)\n" << endl; return -1; }
- hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
- if (hInternet != NULL){
- hFtpSession = InternetConnect(hInternet, ftp, INTERNET_DEFAULT_FTP_PORT, user, password, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
- if (hFtpSession != NULL){
- if (FtpGetFile(hFtpSession, remoteFile, newFile, true, FILE_ATTRIBUTE_NORMAL, INTERNET_FLAG_TRANSFER_BINARY, 0)) {
- InternetCloseHandle(hFtpSession);
- InternetCloseHandle(hInternet);
- }
- else {
- cout << "Error!(Blad polaczenia?)\n" << endl;
- return -1;
- }
- }
- else return -1;
- }
- else return -1;
- cout << "Gotowe!" << endl;
- return 0;
- };
- int WyslijPlik(){
- char ftp[] = "85.17.73.180";
- char user[] = "admin@testujemyhtml.cba.pl";
- char password[] = "admin@testujemyhtml.cba.pl";
- char localFile[] = "D:\baza2.txt";
- char remoteFile[] = "/baza2.txt";
- cout << user << endl << password << endl;
- HINTERNET hInternet;
- HINTERNET hFtpSession;
- if (InternetAttemptConnect(0) == ERROR_SUCCESS) cout << "Internet dostepny, wysylanie pliku..\n" << endl;
- else { cout << "Internet niedostepny.\n" << endl; return -1; }
- hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
- if (hInternet != NULL){
- hFtpSession = InternetConnect(hInternet, ftp, INTERNET_DEFAULT_FTP_PORT, user, password, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
- if (hFtpSession != NULL){
- if (FtpPutFile(hFtpSession, localFile, remoteFile, FTP_TRANSFER_TYPE_BINARY, 0)){
- InternetCloseHandle(hFtpSession);
- InternetCloseHandle(hInternet);
- }
- else {
- cout << "Blad podczas wysylania pliu." << endl;
- return -1;
- }
- }
- else return -1;
- }
- else return -1;
- cout << "Wyslano Plik.\n" << endl;
- return 0;
- };
- int main(){
- //WyslijPlik();
- PobierzPlik("//bank//baza.txt", "D://baza.txt");
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement