-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFTP_3.cpp
More file actions
103 lines (86 loc) · 4.54 KB
/
Copy pathFTP_3.cpp
File metadata and controls
103 lines (86 loc) · 4.54 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// FTP_Final.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
/*
int main() {
FILE *f = fopen("D:\ocr.png", "rb");
FILE *f1 = fopen("D:\ocr2.png", "wb");
if (!f)
return 0;
char *buffer = new char[1024];
int counter = 0;
while (fread(buffer, 1024, 1, f) == 1) {
counter += 1024;
//cout << buffer;
fwrite(buffer, 1024, 1, f1);
memset(buffer, 0, 1024);
}
if (feof(f))
cout << "\nDone\n";
else
cout << "\nError\n";
cout << endl << endl << counter;
return 0;
}
/**/
int main()
{
WSADATA SData;
int iResult = WSAStartup(0x0202, &SData);
if (iResult != 0) {
cout << "KHONG THE KHOI DONG WINSOCK";
return 1;
}
cout << "KHOI TAO SOCKET THANH CONG: \n";
cout << "Phien ban: " << SData.wVersion << "\n";
cout << "Phien ban co the ho tro: " << SData.wHighVersion << "\n";
cout << "Ghi chu: " << SData.szDescription << "\n";
cout << "Thong tin cau hinh: " << SData.szSystemStatus << "\n";
SOCKET sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sockaddr_in my_addr;
sockaddr_in sv_cmd_addr;
int nResult = SetupIPWS(sockfd, my_addr);
if (nResult) {
//Lỗi khi khởi tạo
cout << "Co loi khi khoi tao socket" << endl;
cin.ignore();
return 1;
}
string server_address;
cout << "Nhap dia chi IP server: ";
cin >> server_address;
cin.ignore();
const char* c_serveraddr = server_address.c_str();
//cin >> c_serveraddr;
//cin.ignore();
sv_cmd_addr.sin_addr.s_addr = inet_addr(c_serveraddr);
sv_cmd_addr.sin_port = htons(SERVER_C_PORT);
sv_cmd_addr.sin_family = AF_INET;
cout << "Connecting to FPT server at: " << c_serveraddr << endl;
nResult = Connect(sockfd, sv_cmd_addr);
if (nResult) {
//Gap loi
cout << "Loi khi ket noi server. Chuong trinh se tu dong" << endl;
Sleep(3000);
WSACleanup();
return 1;
}
cout << "Connected on port " << ntohs(my_addr.sin_port) << "!!\n\n";
int timeout = 200;
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(int)))
{
perror("setsockopt");
return -1;
}
char RecvBuf[1024];
recv(sockfd, RecvBuf, 1024, 0);
eom(RecvBuf);
cout << RecvBuf;
Program prog(sockfd, sv_cmd_addr);
nResult = prog.Menu();
closesocket(sockfd);
WSACleanup();
return 0;
}
/**/