How to implement FTP file upload on SCM

This article is written I am also unique online

I began to publish in a blog on the results of Netease is transferred and there may be accidental injury where some characters or words wrong

I will have time to rewrite, now we first looked at

ftp is based on the TCP link

To achieve FTP on the need to achieve single-chip TCP, how (what hardware and software) I do not introduce a lot of the Internet, this FTP is not here briefly under

Prerequisite: Create two links,
one-bit TCP client to connect to the IP FTP servers and 21 ports,
another port if it is linked to a specified FTP server PASV mode when it is idle waiting for data to be transmitted (client mode, Links are required to spend a link command sends a PASV port and get IP)
If pORT mode is another link on server mode for the power to turn on when a link is sent first need to transfer data
(similar to port pORT 192,168,1,102,14,178 No. 14 * 256 + 178) frame format to allow FTP server port FTP21 know that links the port send data

The following describes only the PASV mode

FTP link process:

1 Start the server (how to start FTP server would not have said it) clients connect to the server port 21
2 server returns a welcome message similar to V4.0.0 is available for purchase JDFW FTP 220 Server
3 client sends login account information similar veryzhou the USER
4 server returned to the user the name of the correct information required password password required for veryzhou similar 331
5 client to send password information 123sssttt similar PASS
6 server returns a message similar to the successful landing 230 client:. veryzhou successfully logged in client IP: 192.168.1.102

Optional command: SYST reply 215 WINDOWS emulated by DXMSOFT determine the operating system running on the server.

    REST 100 和 REST 0 回复 350 Restarting at 100. 重新开始传输文件

    PWD   回复  257 "/" is current directory.  显示当前路径

    PASV  回复  227 Entering Passive Mode (192,168,1,102,4,0). 被动模式要求服务器监听某个端口并返回给用户,端口号为4*256+0

    LIST -al 回复  150 Opening ASCII mode data connection for directory list.  获取的文件列表信息

    另一个链接吐出数据:
    07-01-15 07:51PM                  163 123.txt
    07-01-15 08:04PM                   38 53287.txt

         后回复 226 Transfer complete.

Upload a file:

发送  SIZE 53286666.txt   查询53286666.txt的长度,或者说查询这个文件是否存在

回复  550 File not found. 如果不是需要改名  (或者创建不可能重名的文件,则不存在这个问题)
回复  213 78  文件状态(78字节)

发送  PASV  

回复  227 Entering Passive Mode (192,168,1,102,4,0). 被动模式要求服务器监听某个端口并返回给用户

创建TCP客户端连接IP192.168.1.102端口4*256+0    链接成功后

发送  STOR 53286666.txt  保持另外一个链接的数据到文件53286666.txt,如果这个文件存在则覆盖他

回复  150 Opening BINARY mode data connection for file transfer.

另外一个链接发送文件内容  的空间撒谎的卡和数据库的哈萨克觉得好看82374987349857983475983475798347598734

回复(还是21这个链接)226 Transfer complete. 请求的文件操作成功  另外一个链接已经关闭
(ftp服务器判断另外一个链接断开即回复这个,中间另外一个链接可以多次发送)

发送 SITE UTIME /53286666.txt 20150701124829 20150701124829 20150701124829 UTC 写文件创建,修改,访问时间

回复 502 Command not implemented - Try HELP.  出错可以不管他

这里可以再次获取列表信息判断是否传输成功(其实没必要)

You can also delete a file, reading a file waiting for, if you have permission

上面任何一个回复不成功即可中断退出(即全部不成功)

Exit FTP:

发送  QUIT
回复  220 Bye  成功推出

关闭21那个链接即可

Guess you like

Origin blog.51cto.com/4094322/2431329