/* * Copyright (C), 2000-2007 by the monit project group. * All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_STRING_H #include #endif #include "protocol.h" /** * Check the server for greeting code 220 and then send a QUIT and * check for code 221. If alive return TRUE, else, return FALSE. * * @author Jan-Henrik Haukeland, * @author Michael Amster, * * @version \$Id: ftp.c,v 1.27 2007/07/25 12:54:32 hauk Exp $ * * @file */ int check_ftp(Socket_T s) { int status; char buf[STRLEN]; ASSERT(s); if(!socket_readln(s, buf, STRLEN)) { LogError("FTP: error receiving data -- %s\n", STRERROR); return FALSE; } Util_chomp(buf); sscanf(buf, "%d %*s", &status); if(status != 220) { LogError("FTP error: %s\n", buf); return FALSE; } if(socket_print(s, "QUIT\r\n") < 0) { LogError("FTP: error sending data -- %s\n", STRERROR); return FALSE; } if(!socket_readln(s, buf, STRLEN)) { LogError("FTP: error receiving data -- %s\n", STRERROR); return FALSE; } Util_chomp(buf); sscanf(buf, "%d %*s", &status); if(status != 221) { LogError("FTP error: %s\n", buf); return FALSE; } return TRUE; }