doFTPAuth 执行FTP认证
(ctx context.Context, info *common.HostInfo, cred Credential, config *common.Config, state *common.State)
| 78 | |
| 79 | // doFTPAuth 执行FTP认证 |
| 80 | func (p *FTPPlugin) doFTPAuth(ctx context.Context, info *common.HostInfo, cred Credential, config *common.Config, state *common.State) *AuthResult { |
| 81 | target := info.Target() |
| 82 | |
| 83 | conn, err := ftplib.Dial(target, ftplib.DialWithTimeout(config.Timeout)) |
| 84 | if err != nil { |
| 85 | state.IncrementTCPFailedPacketCount() |
| 86 | return &AuthResult{ |
| 87 | Success: false, |
| 88 | ErrorType: classifyFTPErrorType(err), |
| 89 | Error: err, |
| 90 | } |
| 91 | } |
| 92 | state.IncrementTCPSuccessPacketCount() |
| 93 | |
| 94 | err = conn.Login(cred.Username, cred.Password) |
| 95 | if err != nil { |
| 96 | _ = conn.Quit() |
| 97 | return &AuthResult{ |
| 98 | Success: false, |
| 99 | ErrorType: classifyFTPErrorType(err), |
| 100 | Error: err, |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return &AuthResult{ |
| 105 | Success: true, |
| 106 | Conn: &ftpConnWrapper{conn}, |
| 107 | ErrorType: ErrorTypeUnknown, |
| 108 | Error: nil, |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // ftpConnWrapper 包装 ftplib.ServerConn 以实现 io.Closer |
| 113 | type ftpConnWrapper struct { |
no test coverage detected