sprint 1-alpha
sprint/io/network/ftp.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 *   sprint::xftp
00003 *
00004 *   Copyright (C) 2005-2011  Paolo Medici <www.pmx.it>
00005 *
00006 *  This library is free software; you can redistribute it and/or
00007 *  modify it under the terms of the GNU Lesser General Public
00008 *  License as published by the Free Software Foundation; either
00009 *  version 2.1 of the License, or (at your option) any later version.
00010 *
00011 *  This library is distributed in the hope that it will be useful,
00012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 *  Lesser General Public License for more details.
00015 *
00016 *  You should have received a copy of the GNU Lesser General Public
00017 *  License along with this library; if not, write to the Free Software
00018 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 *
00020 *******************************************************************************/
00021 
00022 #ifndef _SPRINT_FTP_H
00023 #define _SPRINT_FTP_H
00024 
00028 #include <sprint/io/network/socket.h>
00029 #include <sprint/io/network/async_socket.h>
00030 
00031 namespace sprint {
00032 
00034 #define HR_OK                           0
00035 #define HR_INVALID_ADDRESS      1
00036 #define HR_CANNOT_CONNECT       2
00037 #define HR_RESPONSE_TIMEOUT     3
00038 #define HR_CANCELLED            4
00039 #define HR_CANNOT_CREATE        5
00040 
00042 
00043 #define DEFAULT_FTP_PORT        21
00044 
00045 enum FtpResponseCode {
00046 FTP_RESPONSE_RESTATRT_MARKER_REPLY = 110,
00047 FTP_RESPONSE_SERVICE_READY_IN_MINUTES = 120,
00048 FTP_RESPONSE_DATA_CONNECTION_ALREADY_OPEN = 125,
00049 FTP_RESPONSE_FILE_STATUS_OK = 150,
00050 FTP_RESPONSE_COMMAND_OK = 200,
00051 FTP_RESPONSE_COMMAND_NOT_IMPLEMENTED_SUPERFLUOUS_AT_THIS_SITE = 202,
00052 FTP_RESPONSE_SYSTEM_STATUS_OR_SYSTEM_HELP_REPLY = 211,
00053 FTP_RESPONSE_DIRECTORY_STATUS = 212,
00054 FTP_RESPONSE_FILE_STATUS = 213,
00055 FTP_RESPONSE_HELP_MESSAGE = 214,
00056 FTP_RESPONSE_NAME_SYSTEM_TYPE = 215,
00057 FTP_RESPONSE_SERVICE_READY_FOR_NEW_USER = 220,
00058 FTP_RESPONSE_SERVICE_CLOSING_CONTROL_CONNECTION = 221,
00059 FTP_RESPONSE_DATA_CONNECTION_OPEN = 225,
00060 FTP_RESPONSE_CLOSING_DATA_CONNECTION = 226,
00061 FTP_RESPONSE_ENTERING_PASSIVE_MODE = 227,
00062 FTP_RESPONSE_USER_LOGGED_IN = 230,
00063 FTP_RESPONSE_REQUESTED_FILE_ACTION_OK_COMPLETED = 250,
00064 FTP_RESPONSE_PATHNAME_CREATED = 257,
00065 FTP_RESPONSE_USER_NAME_OK_NEED_PASSWORD = 331,
00066 FTP_RESPONSE_NEED_ACCOUNT_FOR_LOGIN = 332,
00067 FTP_RESPONSE_REQUESTED_FILE_ACTION_PENDING_FURTHER_INFO = 350,
00068 FTP_RESPONSE_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION = 421,
00069 FTP_RESPONSE_CANNOT_OPEN_DATA_CONNECTION = 425,
00070 FTP_RESPONSE_CONNECTION_CLOSED_TRANSFER_ABORTED = 426,
00071 FTP_RESPONSE_REQUESTED_FILE_ACTION_NOT_TAKEN = 450,
00072 FTP_RESPONSE_REQUESTED_ACTION_ABORTED = 451,
00073 FTP_RESPONSE_REQUESTED_ACTION_NOT_TAKEN = 452,
00074 FTP_RESPONSE_SYNTAX_ERROR_COMMAND_UNRECOGNIZED = 500,
00075 FTP_RESPONSE_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS = 501,
00076 FTP_RESPONSE_COMMAND_NOT_IMPLEMENTED = 502,
00077 FTP_RESPONSE_BAD_SEQUENCE_OF_COMMANDS = 503,
00078 FTP_RESPONSE_COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER = 504,
00079 FTP_RESPONSE_NOT_LOGGED_IN = 530,
00080 FTP_RESPONSE_NEED_ACCOUNT_FOR_STORING_FILES = 532,
00081 FTP_RESPONSE_REQUESTED_ACTION_NOT_TAKEN_FILE_UNAVAILABLE = 550,
00082 FTP_RESPONSE_REQUESTED_ACTION_ABORTED_PAGE_TYPE_UNKNOWN = 551,
00083 FTP_RESPONSE_REQUESTED_FILE_ACTION_ABORTED_EXCEEDED_STORAGE_ALLOCATION = 552,
00084 FTP_RESPONSE_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED = 553,
00085 };
00086 
00087 enum FtpStatus{
00088   FTP_DISCONNECTED,
00089   FTP_USER_LOGGED,
00090   FTP_CONNECTION_AUTHENTICATION,
00091   FTP_CONNECTION_CONNECTED
00092 };
00093 
00094 enum FtpTransferMode {
00095   FTP_ASCII_MODE,
00096   FTP_BINARY_MODE
00097 };
00098 
00099 typedef BOOL (* ENUMFILESCALLBACK) (LPVOID lpContext);
00100 
00102   class ftp {
00103     FtpStatus m_status;
00104     bool m_passive_mode;
00105     
00106     async_socket<socket> m_s;    /* FTP */
00107     socket m_port; /* PORT */
00108     socket m_file; /* Tranfer File Socket */
00109 
00110         UINT uLastFtpResp;
00111         char ftpresp[512];
00112 
00113         bool _ftp;
00114         bool _file;
00115 
00116         DWORD dwFileSize;
00117     
00118     private:
00119       const char *ResponseToString(int hr);
00120       unsigned int GetResponseIdSync(unsigned int uTimeOut, bool bIgnoreComment);
00121       bool Init();
00122       int Disconnect();
00123       char *GetResponse();
00124       unsigned int GetResponseId();
00125       int _setup_transfer();
00126       int _begin_transfer();
00127       int _end_transfer();
00128       int Pasv();
00129       int WaitForIncomingConnection();
00130       int ConnectToServer();
00131       int Port();
00132     public:
00133       ftp();
00134       ~ftp();
00135       
00136       int set_passive_mode(bool bPassiveMode);
00137       int connect(const char * lpszServer, unsigned int nServerPort, const char * lpszUserName, const char * lpszPassword);
00138       int rename(const char * lpszFrom, const char * lpszTo);
00139       int rename_to(const char * lpszTo);
00140       int rename_from(const char * lpszFrom);
00141       int delete_file(const char * lpszFileName);
00142       int remove_directory(const char * lpszDirectory);
00143       int create_directory(const char * lpszDirectory);
00144       int set_current_directory(const char * lpszCurrentDirectory);
00145       int get_current_directory(LPSTR lpszCurrentDirectory, unsigned int dwBufSize);
00146       
00147       int ftp_command(const char * lpszCommand);
00148 
00149       int get_file(const char * lpszRemoteFile, const char * lpszNewFile);
00150       int write_file(const char *lpBuffer, unsigned int dwBytesToWrite, unsigned int *lpdwBytesWrited);
00151       int read_file(char *lpBuffer, unsigned int dwBytesToRead, unsigned int *lpdwBytesReaded);
00152       int close_file();
00153       
00154   };
00155 }
00156 
00157 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines