About openat ftpclient (pure C implementation)

Source: Internet
Author: User
Tags ftp commands ftp client ftp protocol

 

It has been a while for openat development. It is not a good time to calculate this period.
Openat is a system platform provided by Wavecom to encapsulate networks, controls, and provide powerful secondary development interfaces.
Because the platform is encapsulated, we don't need to know much about the underlying system. We just need to know how it works. This is a very favorable entry platform for most embedded developers.
However, because of its encapsulation of the underlying system, many restrictions are imposed. For example, after the serial port is throttled, only 120 bytes can be received at a time. If large data communication is required, the serial port must be processed.
In terms of TCP/IP and GPRS, Wavecom completely encapsulates the entire protocol. We only need to perform simple system configuration to connect to the Internet, no link layer or transport layer ......
Wavecom should have done a good job in Protocol optimization. On my platform (based on mobile, static, q24plus), the uplink speed is about 1.5kbyte-2 Kbyte, And the downlink speed is stable: 4.5 Kbyte (FTP download)

Today I am mainly talking about the implementation of the FTP client.

For FTP, it is actually an encapsulation protocol based on TCP/IP. The openat SDK of Wavecom also has the FTP Client/Server development function, but I don't know why, wavecom imposes limits on Chinese sales platforms

And some functions are locked by logic, so that we cannot use them normally.
The FTP client is one of them. When using the FTP client, the system prompts errlog ftp. C: 101: Internet Protocol feature not activated.

After understanding with the dealer, I learned that q24plus points 411 and 408,408 cannot use the module embedded FTP client. If you want to use it, you have to use 411, but it costs a few US dollars.
I want to come and think that the Wavecom buddy is too unfriendly. In this case, I need to pay more for the difference.

Because the modules we bought are all in the 408 series, we can only find another way to implement them, instead of using the ftpclient that comes with the openat SDK.

I have already stated that the FTP protocol is an encapsulation protocol based on the TCP/IP protocol, and its communication mode is TCP data packets. With this foundation, I am going to use the TCP socket provided by the openat SDK to implement

Ftpclient.

Before implementation, we need to understand how FTP works.

The FTP server has two working modes: Port and PASV. For port, the client must have a public IP address (or the client can "directly" communicate with the server ), PASV only requires the client to communicate with the server, and does not require a public IP.

The project is based on mobile GPRS, and there is no public IP after GPRS is pulled, so the server can only work in PASV mode, currently popular FTP server tools on the market, this mode is supported (for example, Serv-U ).
When FTP is working, there will be two TCP communications, one is called the FTP command and the other is the FTP data. The FTP data socket is used for data upload and download (for example, uploading images to the server, download files to the local machine); FTP command is

For protocol communication with the FTP server, various communications between the client and the server are transmitted through this channel.

FTP protocol format:

Slave> host
Command Header space Parameter

Host> slave
Status Code Space Description

The reason why I use FTP client is that I want to remotely update Wavecom openat and download data from the server, I only need to be able to log on to the server normally and download the specified file to my running platform.

There is a complete FTP communication.

The following are the FTP server statuses and Protocols I use:
Host> slave
150 start Data Transmission
200 set transfer mode (type I)
220 server ready, waiting for username
226 data download complete
227 set the server working mode (psav) to normal
230 User Logon successful
331 the user name is normal, waiting for the password
350 resumable upload succeeded
530 TCP connection timeout
550 the remote server does not have the requested file.

Slave> host
User Username logon Username
Pass Password Logon Password
PASV sets the server Passive working mode
RETR file name request file name
The start position of the rest file. The request position for resumable data transfer.

Openat SDK implements FTP client process
1. Create two global TCP channels, one for FTP commands and the other for FTP data transmission.
2. log on to the server using FTP commands
3. Set the server working mode: passive mode PASV
After executing this command, the client will receive the following prompt:
Response: 227 entering passive mode (IP1, ip2, IP3, ip4, port1, port2)
Ip1.ip2. ip3.ip4 is the IP address of the server.
The port2 server waits for the data connection port of the client. The port number is calculated as: port1 * 256 + port2
4. Use the FTP data channel to connect the address and port you just received
5. Send the file retrieval command to the FTP Command Channel. If the FTP data channel is established normally, the data packet sent from the server will be received.

 

I spent two days coding and debugging the above functions. Currently, the entire process works normally.

 

 

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.