Пример #1
0
/**
 * TCPServerOpen - Creates a TCP server on specified port 
 * \param tcpport - Number of the port for the server. Example: "1234" (the array must be NULL terminated).
 * \return - INVALID_SOCKET: the operation was failed. Maybe there are not available sockets.
 * \return - A TCP_SOCKET handle to the created socket. It must be used to access the socket in the program (read/write operations and close socket).
 */
TCP_SOCKET TCPServerOpen (char tcpport[])
{			
	return TCPGenericOpen("127.0.0.1" , 0 , tcpport , 1);
}
Пример #2
0
/**
 * Open a PassiveMode data exchange between Flyport (Client) and the ServerName
 * \param sockpasv - The handle of the socket for commands exchange.
 * \param ServerName - The server data IP returned by the FTP Server
 * \return The TCP_SOCKET to use for data transfer in Passive Mode.
 */
TCP_SOCKET FTPClientPasv(TCP_SOCKET sockpasv, char ServerName[])
{	
	unsigned long int dataport=0;
	char *word;
	char word1[10];
	char buffertot[100];
	char servReply[30];
	int counter = 0;
		
	FTPRxFlush(sockpasv, 100);
	BYTE strpasv[]={"pasv\r\n"};
	FTPMultiWrite(sockpasv,strpasv,6);
	
	while (FTPRxLen(sockpasv) == 0)
	{
		vTaskDelay(10);
		counter++;
		if (counter == 50)
			break;
	}
	counter = 0;
	
	int indsum=0;
	while (FTPRxLen(sockpasv)>0)
	{
		int toread = FTPRxLen(sockpasv);
		FTPRead(sockpasv , (char *) (buffertot+indsum) , toread);
		indsum += toread;
		while (FTPRxLen(sockpasv) == 0)
		{
			vTaskDelay(10);
			counter++;
			if (counter == 20)
				break;
		}		
	}
	
	word = strtok(buffertot,",()");

	int indsub=1;
	while (word != NULL)
	{
		word = strtok(NULL, ",()");
		if (indsub == 1)
		{
			sprintf(servReply, "%s", word);
			strcat(servReply, ".");
		}
		if (indsub == 2)
		{
			strcat(servReply, word);
			strcat(servReply, ".");
		}
		else if (indsub == 3)
		{
			strcat(servReply, word);
			strcat(servReply, ".");
		}
		else if (indsub == 4)
		{
			strcat(servReply, word);
		}
		else if (indsub == 5)
		{
			dataport=atoi(word);
			dataport=dataport*256;
			int xy;
			xy=sprintf(word1,"%li",dataport);			
		}
		else if (indsub == 6)
		{
			dataport += atoi(word);
			sprintf(word1,"%li",dataport);
		}
		indsub++;
	}

	xFrontEndStatRet = 2;	
	ToSend=20;
	sprintf(ServerName, "%s", servReply);
	return TCPGenericOpen(ServerName, TCP_OPEN_RAM_HOST , word1 , 4);	
}
Пример #3
0
/**
 * TCPClientOpen - Creates a TCP client on specified IP address and port
 * \param tcpaddr - IP address of the remote server. Example: "192.168.1.100" (the char array must be NULL terminated).
 * \param tcpport - Port of the remote server to connect. Example: "1234" (the char array must be NULL terminated).
 * \return - INVALID_SOCKET: the operation was failed. Maybe there are not available sockets.
 * \return - A TCP_SOCKET handle to the created socket. It must be used to access the socket in the program (read/write operations and close socket).
 */
TCP_SOCKET TCPClientOpen (char tcpaddr[] , char tcpport[])
{
	return TCPGenericOpen(tcpaddr , 2 , tcpport , 0);
}
Пример #4
0
/**
 * Creates an FTP client on specified IP address and port
 * \param ftpaddr - IP address of the remote server. Example: "192.168.1.100" (the char array must be NULL terminated).
 * \param ftpport - Port of the remote server to connect. Example: "1234" (the char array must be NULL terminated).
 * \return - INVALID_SOCKET: the operation was failed. Maybe there are not available sockets.
 * \return - A TCP_SOCKET handle to the created socket. It must be used to access the socket in the program (read/write operations and close socket).
 */
TCP_SOCKET FTPClientOpen (char ftpaddr[] , char ftpport[])
{
	return TCPGenericOpen(ftpaddr , 1 , ftpport , 3);
}