juchiast / ftp Goto Github PK
View Code? Open in Web Editor NEWFTP client implementation in C++
FTP client implementation in C++
Các lệnh không cần giao tiếp với server:
Thầy yêu cầu chương trình chạy thông suốt, không bị đứng.
Phần này sẽ chỉnh sửa hàm TcpStream::read
và TcpStream::write
để lúc người dùng bấm <CTRL+C> thì dừng việc gửi nhận dữ liệu, xong throw để hàm gọi có thể catch rồi xử lý.
Xem chỗ nào có thể bị đứng rồi sửa chỗ đó :v
Hoặc dùng thread, đơn giản hơn.
Khi người dùng bấm <CTRL+C> thì signal SIGINT sẽ được gửi cho chương trình, mặc định thì chương trình sẽ dừng.
Hiện tại read
và write
gọi syscall send
và recv
, vì sockfd
không ở nonblock mode nên 2 hàm này sẽ block thread hiện tại cho tới khi gửi, nhận xong.
Cách cài:
TcpStream::sockfd
(set trong constructor)signalfd
và poll
để chờ 1 trong 2 sự kiện xảy ra: nhận SIGINT hoặc gửi/nhận dữ liệu xong. Rồi xử lý tương ứng.Cần xem kĩ làm cách nào để dừng việc gửi nhận dữ liệu.
Tài liệu:
Hiện tại chỉ mới có passive mode :v
Có vài việc cần làm khi cài:
Ftp::port_or_pasv
Ftp::setup_data_connection
. Làm 2 việc song song: đọc reply của server, mở data connection, vì nếu lệnh bị lỗi thì có thể server sẽ không mở kết nối.Ftp::active
và Ftp::passive
để chọn mode (gán lại bool Ftp::active
thôi, không cần gửi nhận gì với server)Lúc test active mode nên dùng server trên máy ảo có địa chỉ IP khác máy thật.
Hiện tại class TcpStream
chỉ kết nối được đến địa chỉ IP.
Phần này sửa lại constructor của TcpStream
để có thể dùng domain name hoặc IP.
Lấy địa chỉ IP từ domain name bằng getaddrinfo
:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.