1、FTP返回码列表(哪里都能找到的):

120 Service ready in NNN minutes.
服务在NNN时间内可用
-----------------------------------
125 Data connection already open; transfer starting.
数据连接已经打开,开始传送数据.
-----------------------------------
150 File status okay; about to open data connection.
文件状态正确,正在打开数据连接.
-----------------------------------
200 Command okay.
命令执行正常结束.
-----------------------------------
202 Command not implemented, superfluous at this site.
命令未被执行,此站点不支持此命令.
-----------------------------------
211 System status, or system help reply.
系统状态或系统帮助信息回应.
-----------------------------------
212 Directory status.
目录状态信息.
-----------------------------------
213 File status. $XrkxmL=
文件状态信息.
-----------------------------------
214 Help message.On how to use the server or the meaning of a particular non-standard command. This reply is useful only to the human user.
帮助信息。关于如何使用本服务器或特殊的非标准命令。
-----------------------------------
215 NAME system type. Where NAME is an official system name from the list in the Assigned Numbers document.
NAME系统类型。
-----------------------------------
220 Service ready for new user.
新连接的用户的服务已就绪
-----------------------------------
221 Service closing control connection.
控制连接关闭
-----------------------------------
225 Data connection open; no transfer in progress.
数据连接已打开,没有进行中的数据传送
-----------------------------------
226 Closing data connection. Requested file action successful (for example, file transfer or file abort).
正在关闭数据连接。请求文件动作成功结束(例如,文件传送或终止)
-----------------------------------
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
进入被动模式
-----------------------------------
230 User logged in, proceed. Logged out if appropriate.
用户已登入。 如果不需要可以登出。
-----------------------------------
250 Requested file action okay, completed.
被请求文件操作成功完成 63
-----------------------------------
257 "PATHNAME" created.
路径已建立
-----------------------------------
331 User name okay, need password.
用户名存在,需要输入密码
-----------------------------------
332 Need account for login.
需要登陆的账户
-----------------------------------
350 Requested file action pending further inFORMation U
对被请求文件的操作需要进一步更多的信息
-----------------------------------
421 Service not available, closing control connection.This may be a reply to any command if the service knows it must shut down.
服务不可用,控制连接关闭。这可能是对任何命令的回应,如果服务认为它必须关闭
-----------------------------------
425 Can't open data connection.
打开数据连接失败
-----------------------------------
426 Connection closed; transfer aborted.
连接关闭,传送中止。
-----------------------------------
450 Requested file action not taken.
对被请求文件的操作未被执行
-----------------------------------
451 Requested action aborted. Local error in processing.
请求的操作中止。处理中发生本地错误。
-----------------------------------
452 Requested action not taken. Insufficient storage space in system.File unavailable (e.g., file busy).
请求的操作没有被执行。系统存储空间不足。 文件不可用
-----------------------------------
500 Syntax error, command unrecognized. This may include errors such as command line too long.
语法错误,不可识别的命令。 这可能是命令行过长。
-----------------------------------
501 Syntax error in parameters or arguments.
参数错误导致的语法错误
-----------------------------------
502 Command not implemented.
命令未被执行
-----------------------------------
503 Bad sequence of commands.
命令的次序错误。
-----------------------------------
504 Command not implemented for that parameter.
由于参数错误,命令未被执行
-----------------------------------
530 Not logged in.
没有登录
-----------------------------------
532 Need account for storing files.
存储文件需要账户信息!
-----------------------------------
550 Requested action not taken. File unavailable (e.g., file not found, no access).
请求操作未被执行,文件不可用。
-----------------------------------
551 Requested action aborted. Page type unknown.
请求操作中止,页面类型未知
-----------------------------------
552 Requested file action aborted. Exceeded storage allocation (for current directory or dataset).
对请求文件的操作中止。 超出存储分配
-----------------------------------
553 Requested action not taken. File name not allowed
请求操作未被执行。 文件名不允许
 
2、状态探测过程

HITE_LOGGER::instance().logDebug("开始探测FTP状态");
            if(client.connectTo("127.0.0.1", 21, sc))
            {
                client.recvFrom(szbuf,128);

std::string lsr = szhite_gvp::__Format("USER root\r\nPASS 123456\r\n");
                int ret = client.sendTo(lsr.c_str(), lsr.length());
                client.recvFrom(szbuf,128);
                lsr = szbuf;

if(lsr.find("230") != std::string::npos)
                {
                    CurState.StatusType = 7;
                }
                else
                {
                    client.recvFrom(szbuf,128);
                    lsr = szbuf;
                    if(lsr.find("230") != std::string::npos)
                    {
                        CurState.StatusType = 7;
                    }
                    else
                    {
                        CurState.StatusType = 6;
                    }
                }
                client.close();
            }
            else
            {
                std::cout << "port 21 is disable"<<std::endl;
                CurState.StatusType = 6;
            }
           Sleep(5000);
  
    这里是使用的自己封装的TCP类,client作为客户端,初始化步骤正常操作,连接的时候连接目标FTP的IP及对应端口
    第一次连接完服务端一般会返回一些东西,微软的IIS6.0-FTP上返回为“220 Microsoft FTP Service”,ServU返回为“220 Serv-U FTP Server v6.3 for WinSock ready...”,其他服务端没有测试,反正一般根据返回字符串里面的220代码来判断连接是否正常

  然后发送自己的账号密码,上面测试代码里面用的是root/123456的用户及密码,此处返回值为

“331 User name okay, need password.
User logged in, proceed.”

可以在字符串里面找到230作为验证账号登陆是否成功,失败则服务端返回

“331 User name okay, need password.
Not logged in.”

根据530来判断账号登录失败。

实际测试发现,这两条服务端返回有时是一次发过来,有时会分两次发过来,所以在第一次找230失败的时候再接收一次,以防止服务端第二次才发送FTP登录状态。也可以按顺序先发账号,再发密码。

3、总结

  这种方式是通过socket通信向服务端发送基本的FTP操作指令,做一些简单的状态探测比较方便,但是复杂的操作还是用别的方式效率更佳。

探测FTP状态,socket方式的更多相关文章

  1. 程序中保存状态的方式之Cookies

    程序中保存状态的方式之 Cookies,之前写过一篇关于ViewState的.现在继续总结Cookies方式的 新建的测试页面login <%@ Page Language="C#&q ...

  2. HTTP 和FTP 状态信息总结(留着自己用)

    HTTP 状态信息 HTTP 400 – 请求无效HTTP 401.1 – 未授权:登录失败HTTP 401.2 – 未授权:服务器配置问题导致登录失败HTTP 401.3 – ACL 禁止访问资源H ...

  3. HTTP、FTP状态码 (share)

    来源:http://www.cnblogs.com/setsail/archive/2012/03/23/2413577.html HTTP1xx - 信息提示(这些状态代码表示临时的响应.客户端在收 ...

  4. 程序中保存状态的方式之ViewState

    程序中保存状态的方式有以下几种: 1.Application 2.Cookie 3.Session 4.ViewState:ViewState是保存状态的方式之一,ViewState实际就是一个Hid ...

  5. 使用socket方式连接Nginx优化php-fpm性能

    Nginx连接fastcgi的方式有2种:TCP和unix domain socket 什么是Unix domain socket?-- 维基百科 Unix domain socket 或者 IPC ...

  6. lnmp使用socket方式连接nginx优化php-fpm性能

    lnmp使用socket方式连接nginx优化php-fpm性能 Nginx连接fastcgi的方式有2种:TCP和unix domain socket 什么是Unix domain socket?- ...

  7. php, hhvm与odp & Unix domain Socket方式

    接上一篇,复习一下 启动php或hhvm: php/sbin/php-fpm start hhvm/bin/hhvm_control start 启动nginx或lighttpd: webserver ...

  8. HTTP、FTP状态码 汇总

    原文:HTTP.FTP状态码 汇总 HTTP1xx - 信息提示(这些状态代码表示临时的响应.客户端在收到常规响应之前,应准备接收一个或多个 1xx 响应. ) • 100 - 继续.• 101 - ...

  9. 重载Python FTP_TLS 实现Implicit FTP Over TLS方式下载文件

    对于Python2.7来说,内置的FTP_TLS类并不支持Implicit FTP Over TLS加密方式的FTP Server操作,为支持Implicit FTP Over TLS加密方式,必须重 ...

随机推荐

  1. 毛笔笔锋算法IOS版

    http://www.merowing.info/2012/04/drawing-smooth-lines-with-cocos2d-ios-inspired-by-paper/#.VUln2_mqp ...

  2. js颠倒数组元素顺序reverse()

    颠倒数组元素顺序reverse() reverse() 方法用于颠倒数组中元素的顺序. 语法: arrayObject.reverse() 注意:该方法会改变原来的数组,而不会创建新的数组. 定义数组 ...

  3. Spring的测试

    spring测试要引用junit及spring-test <dependency> <groupId>junit</groupId> <artifactId& ...

  4. Vim 键盘指令高清图

    个人感觉挺好用的 推荐大家使用windows版的vim,个人用着感觉不错,在linux上用惯了vim的朋友可以试试这个.

  5. nginx部分命令

    启动nginx start nginx 停止nginx nginx -s stop 重启nginx nginx -s reload 查看版本信息 nginx -v 大写V是查看配置信息 查看nginx ...

  6. 一则奇怪的案例处理:ORA-00257: archiver error. Connect internal only, until freed

    前天,业务反应数据库不能连接 在操作系统通过字符串尝试登陆数据库报:ORA-00257: archiver error. Connect internal only, until freed 解决思路 ...

  7. Linux安装Go语言

    1.下载Go语言安装包https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz 2.在命令行执行如下命令: sudo tar - ...

  8. Sublime Text3 安装markdown插件

    1.打开Sublime Text,使用快捷键 ctrl+` (左上角Tab键上方,Esc键下方)或者使用菜单 View > Show Console menu,此时将出现Sublime Text ...

  9. python split函数

    Python split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串 例 current_month = "2013-01-02" y ...

  10. HDU-1203(01背包)

    I NEED A OFFER! Problem Description Speakless 很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了.要申请国外的 ...