In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you about how to use the finite state machine to achieve FTP file transfer. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Function description
For FTP file transfer, we use C++ 's class to implement, and define a FTPClient C++ class in this class.
The object defines six common functions: Init (), SendFile (), ReceiveFile (), Do (), Resume (), and Stop ()
Function. Each function is described in detail below.
(1) int Init (char * host, char * FTPusername, char * FTPpassword, unsigned
Long timeout, int FTPMode)
Function description:
Initialize set FTP file transfer parameters.
Enter parameters:
The second embedded system Application Program of Yingchuang Information Technology Co., Ltd.
Www.emtronix.com 2 028-86180660
Char * the IP address of the host remote host, such as "192.168.201.34".
Char * the user name that FTPusername uses when logging in, such as "guest"
Char * password used when FTPpassword logs in, such as "888"
Timeout time, in milliseconds, as defined by unsigned long timeout.
Int FTPMode login mode of FTP, = 0 is the standard mode
= 1 is passive mode
Return value:
! = 0 the function call failed
= 0 the function was called successfully
Note:
This function needs to be called only once during system initialization.
(2) int SendFile (char * file, int mode)
Function description:
As a FTP client, start sending files to the remote FTP server.
Enter parameters:
Char * the filename of the file being manipulated, such as "myfile.txt".
Int mode = 0; send ASCII file from remote server
= 1; send binary files from the remote server
Return value:
! = 0 the function call failed
= 0 the function was called successfully
(3) int ReceiveFile (char * file, int mode)
Function description:
Start fetching files from a remote FTP server as a FTP client.
Enter parameters:
Char * the filename of the file being manipulated, such as "myfile.txt".
Int mode = 0; get ASCII file from remote server
= 1; get binary files from the remote server
The second embedded system Application Program of Yingchuang Information Technology Co., Ltd.
Www.emtronix.com 3 028-86180660
Return value:
! = 0 the function call failed
= 0 the function was called successfully
(4) int Do ()
Function description:
Execute a remote FTP server to send files or get files from a remote FTP server as a FTP client
The FTP file transfer is successful only if the return value of the function is 0.
Return value:
= 0 FTP file transferred successfully.
< 0 FTP 文件传输失败,并返回相应的错误代码。 >The state of the 0 FTP file transfer process.
(5) int Resume ()
Function description:
When you call the Do () function to return the FTP transfer failure, you can start the file breakpoint resume function by calling this function, and then
Cooperate with the call to Do () function to complete the transfer of the rest of the file.
(6) int Stop ()
Function description:
Terminates the current FTP file transfer.
Function call
In the specific application, first call the Init () function to initialize and set the relevant parameters of the FTP transmission, and use the
The SendFile () and RecieveFile () functions start the FTP file transfer, and then the application keeps calling the Do () function to enter the
Line FTP file transfer, the application can directly check the return value of the function to determine whether the FTP file transfer is successful.
In the routine APP2.PRJ we provide, we use these functions provided by the FTPCLient class to transfer any FTP file.
Business. Through CMD_TICK to start the FTP file transfer task CMD_FTP, CMD_TICK is automatically generated by the system.
The second embedded system Application Program of Yingchuang Information Technology Co., Ltd.
Www.emtronix.com 4028-86180660
In the execution of CMD_FTPDO, the function Do () is called to determine whether the FTP file transfer is completed by its return value, such as
If it is not finished, continue to send the command so that the program will not block the transfer of FTP files.
You can perform other operations, such as interrupting the resulting command. If the return value is 1) strcpy (FTPFileName, argv [1])
Else strcpy (FTPFileName, "ftpclnt2.exe")
If (argc > 2) i1 = atoi (argv [2])
Else i1 = 3
If (i1&0x02)
{
Printf ("send file% Sporin", FTPFileName)
PFTPClnt- > SendFile (FTPFileName, i1)
}
Else
{
Printf ("receive file% Sporin", FTPFileName)
PFTPClnt- > ReceiveFile (FTPFileName, i1)
}
CmdQueue.PushCmd (CMD_FTPDO)
FTPDone = 1
Break
Case CMD_FTPDO:
I1 = pFTPClnt- > Do ()
If (i1 > 0)
{
Xlen = pFTPClnt- > XLength ()
If (xlen > = 0) printf ("2d 7ld / r", i1, xlen)
CmdQueue.PushCmd (CMD_FTPDO); / / keep going
}
Else if (i1)
< 0 ) { printf( "/nFTP fail %d/n", i1 ); printf( "FTP resume!/n" ); pFTPClnt->Resume ()
CmdQueue.PushCmd (CMD_FTPDO); / / keep going
}
Else
{
Printf ("/ nFTP do okaPao")
FTPDone = 0
The second embedded system Application Program of Yingchuang Information Technology Co., Ltd.
Www.emtronix.com 6028-86180660
}
Break
Default: ExitFlag = 1; / / illegal command, exit
}
If (ExitFlag) break
}
SysExit ()
Return 0
}
/ / return = 0: ok!
/ /
< 0: fail int SysInit( int argc, char** argv ) { int i1; pFTPClnt = new class FTPClientManager( ); pFTPClnt->Init ("222.210.195.109", "guest", "10000", 0)
/ / EnableWDT (10.0) / / 10 sec Watchdog
CmdQueue.StartQueue ()
Return 0
/ / Let's go to main loop!!
}
Int SysExit ()
{
CmdQueue.StopQueue ()
Delete pFTPClnt
Return 0
/ / Let's go back to DOS
}
The above is the editor for you to share how to use the finite state machine to achieve FTP file transfer, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.