1 /* 2 * Copyright 1998-1999 Be, Inc. All Rights Reserved. 3 * Copyright 2003-2019 Haiku, Inc. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef FTP_CLIENT_H 7 #define FTP_CLIENT_H 8 9 10 #include <stdio.h> 11 #include <string> 12 13 #include <File.h> 14 #include <NetAddress.h> 15 #include <NetEndpoint.h> 16 17 #include "FileUploadClient.h" 18 19 using std::string; 20 21 22 /* 23 * Definitions for the TELNET protocol. Snarfed from the BSD source. 24 */ 25 #define IAC 255 26 #define DONT 254 27 #define DO 253 28 #define WONT 252 29 #define WILL 251 30 #define xEOF 236 31 32 33 class FtpClient : public FileUploadClient { 34 public: 35 FtpClient(); 36 ~FtpClient(); 37 38 bool Connect(const string& server, 39 const string& login, 40 const string& passwd); 41 42 bool PutFile(const string& local, 43 const string& remote, 44 ftp_mode mode = binary_mode); 45 46 bool GetFile(const string& remote, 47 const string& local, 48 ftp_mode mode = binary_mode); 49 50 bool MoveFile(const string& oldPath, 51 const string& newPath); 52 bool ChangeDir(const string& dir); 53 bool PrintWorkingDir(string& dir); 54 bool ListDirContents(string& listing); 55 bool Chmod(const string& path, const string& mod); 56 57 void SetPassive(bool on); 58 59 protected: 60 enum { 61 ftp_complete = 1UL, 62 ftp_connected = 2, 63 ftp_passive = 4 64 }; 65 66 bool _TestState(unsigned long state); 67 void _SetState(unsigned long state); 68 void _ClearState(unsigned long state); 69 70 bool _SendRequest(const string& cmd); 71 bool _GetReply(string& outString, int& outCode, 72 int& codeType); 73 bool _GetReplyLine(string& line); 74 bool _OpenDataConnection(); 75 bool _AcceptDataConnection(); 76 77 unsigned long fState; 78 BNetEndpoint* fControl; 79 BNetEndpoint* fData; 80 81 }; 82 83 #endif // FTP_CLIENT_H 84