Home > Software engineering >  FTP PORT model to get the data accept has been blocked with filezilla active mode connection is OK
FTP PORT model to get the data accept has been blocked with filezilla active mode connection is OK

Time:11-18

Struct sockaddr_in addr.
Int data_sockfd conn_sock, port;

Conn_sock=socket (PF_INET SOCK_STREAM, 0).
If (conn_sock==1)
{
Printf ("====% d connect is the error \ n ", __LINE__);
return ;
}

Memset ((char *) & amp; Addr, 0, sizeof (addr));
Addr. Sin_family=AF_INET;
Addr. Sin_addr. S_addr=htonl (INADDR_ANY);
//addr. Sin_port=htons (20);

If (bind (conn_sock, (struct sockaddr *) & amp; Addr, sizeof (addr))==1) {
Close (conn_sock);
Printf ("====% d connect is the error \ n ", __LINE__);
return ;
}

If (listen (conn_sock, SOMAXCONN)==1) {
Close (conn_sock);
Printf ("====% d connect is the error \ n ", __LINE__);
return ;
}

Len=sizeof (struct sockaddr);
If (getsockname (conn_sock, (struct sockaddr *) & amp; Addr, (socklen_t *) & amp; Len)==1)
{
Close (conn_sock);
return ;
}
Port=addr. Sin_port;

If (getsockname (control_sockfd, (struct sockaddr *) & amp; Addr, (socklen_t *) & amp; Len)==1)//when the created socket
{
Close (conn_sock);
return ;
}

Memset (com, 0 ();
Memset (recvline, 0, FTP_DATE_MAXSIZE);


Sprintf (com, "PORT % d, % d, % d, % d, % d, % d \ r \ n",
Addr. Sin_addr. S_addr & amp; 0 x000000ff,
(addr. Sin_addr. S_addr & amp; 0 x0000ff00) & gt;> 8,
(addr. Sin_addr. S_addr & amp; 0 x00ff0000) & gt;> 16,
(addr. Sin_addr. S_addr & amp; 0 xff000000) & gt;> 24,
Port> 8, port& 0 XFF);
if(! Ftp_socket_command (com, "200", recvline))
return ;//send command, receive the server message 200 PORT command successful. Consider using PASV,


Struct sockaddr_in peerServer;
Int acceptfd=1;
Socklen_t len_1=sizeof (peerServer);
Data_sockfd=accept (conn_sock, (struct sockaddr *) & amp; PeerServer, & amp; Len_1);//has been blocked
If (1==data_sockfd)
{
Printf ("====% d connect is the error \ n ", __LINE__);
Return cur_fg_dir;
}
  • Related