C + + Builder platform uses INDY9 to develop automatic FTP programs 01

Source: Internet
Author: User
Tags socket error connection reset ftp client

Indy9 and CB with Indy8 different places still quite a lot of. The first is the icon becomes beautiful, followed by a lot of method are rewritten. It is mainly based on the functions in the Delph, and strive to communicate with them. The differences are described in subsequent chapters of this series.

Before writing the FTP code, it is very necessary to understand the relevant knowledge of the FTP network. Borrow Binny's blog again:

When using FTP, if all the ports between the client machine and the FTP server are open, there is no problem with the connection. If there is a firewall between the client and the server, if the fire prevention policy is not configured and the appropriate connection mode is used, the login will be successful, but the list of problems cannot be listed. To avoid this problem, first understand the FTP mode of operation.

1.FTP port (Active mode) and PASV (passive mode)

(1) PORT (active mode)

Port Chinese is called active mode, the principle of work: the FTP client connects to the FTP server 21 port, send the user name and password login, after successful login to list or read data, the client randomly open a port (more than 1024), send the port command to the FTP server, Tell the server client to take the active mode and open the port; After the FTP server receives the port Active mode command and port number, it sends the data through the server's port 20 port and the client open ports connection, the principle is as follows:

(2) PASV (passive mode)

PASV is the abbreviation of passive, Chinese becomes passive mode, working principle: FTP client connects to FTP server 21 port, send user name and password login, after successful login to list or read data, send PASV command to FTP server, The server randomly opens a port (over 1024) locally, and then tells the client that the open port is connected to the server's open port for data transfer, such as:

When using

Idftp1->connect ()

When connecting to FTP, it is best to understand whether the FTP mode is active or passive. reflected in the code as

Idftp1->passive

However, due to the diversity of FTP servers, there are often various socket error. Enclose the complete error here

Socket Error 0-directly send error
Socket Error 10004-interrupted function call
Socket Error 10013-permission denied
Socket Error 10014-bad Address
Socket Error 10022-invalid argument
Socket error 10024-too many open files
Socket Error 10035-resource temporarily unavailable
Socket error 10036-operation now in progress
Socket error 10037-operation already in progress
Socket error 10038-socket operation on Non-socket
Socket Error 10039-destination address required
Socket Error 10040-message too long
Socket error 10041-protocol wrong type for socket
Socket Error 10042-bad protocol option
Socket Error 10043-protocol not supported
Socket error 10044-socket type not supported
Socket Error 10045-operation not supported
Socket error 10046-protocol Family not supported
Socket error 10047-address family not supported by protocol family
Socket error 10048-address already in use
Socket Error 10049-cannot Assign requested address
Socket Error 10050-network is down
Socket Error 10051-network is unreachable
Socket error 10052-network dropped connection on reset
Socket error 10053-software caused connection abort
Socket error 10054-connection Reset by peer
Socket error 10055-no Buffer space available
Socket error 10056-socket is already connected
Socket error 10057-socket is not connected
Socket error 10058-cannot send after socket shutdown
Socket Error 10060-connection timed out
Socket Error 10061-connection refused
Socket Error 10064-host is down
Socket error 10065-no route to host
Socket Error 10067-too many processes
Socket Error 10091-network subsystem is unavailable
Socket error 10092-winsock. DLL version out of range
Socket error 10093-successful WSAStartup not yet performed
Socket error 10094-graceful shutdown in progress
Socket error 11001-host not found
Socket error 11002-non-authoritative Host not found
Socket error 11003-this is a non-recoverable error
Socket error 11004-valid name, no data record of requested type

Wsaeaddrinuse (10048) Address already in use
Wsaeconnaborted (10053) software caused connection abort
WSAECONNREFUSED (10061) Connection refused
Wsaeconnreset (10054) Connection Reset by peer
Wsaedestaddrreq (10039) Destination address required
Wsaehostunreach (10065) No route to host
Wsaemfile (10024) Too many open files
Wsaenetdown (10050) Network is down
Wsaenetreset (10052) Network dropped connection
Wsaenobufs (10055) No buffer space available
Wsaenetunreach (10051) Network is unreachable
Wsaetimedout (10060) Connection timed out
Wsahost_not_found (11001) Host not FOUND
Wsasysnotready (10091) Network sub-system is unavailable
Wsanotinitialised (10093) WSAStartup () not performed
Wsano_data (11004) Valid name, no DATA of that type
Wsano_recovery (11003) non-recoverable query error
Wsatry_again (11002) non-authoritative host found
wsavernotsupported (10092) wrong WinSock DLL version

Additionally, the problem that arises is "Project Ftp01.exe raised exception class eidconnclosedgracefully with message ' Connection Closed Gracefully .‘. Process stopped.  Use Step or Run continue. " This is a disconnect request initiated by the server side. This problem is caused by the network does not recognize its protocol, it is actually a VCL-like exception handling, can be eliminated after compiling the EXE. The way to avoid this is to add an ordinance (eidsilentexception) in the CB Tools option, debugger options, Language exceptions

C + + Builder platform uses INDY9 to develop automatic FTP programs 01

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.