Arduino TinyFTP
Loading...
Searching...
No Matches
FTPCommon.h
1#pragma once
2
3#include "Arduino.h"
4#include "Client.h"
5#include "IPAddress.h"
6#include "Stream.h"
7
8#ifndef FTP_USE_NAMESPACE
9#define FTP_USE_NAMESPACE true
10#endif
11
12#ifndef FTP_ABORT_DELAY_MS
13#define FTP_ABORT_DELAY_MS 300
14#endif
15
16#ifndef FTP_COMMAND_BUFFER_SIZE
17#define FTP_COMMAND_BUFFER_SIZE 300
18#endif
19
20#ifndef FTP_RESULT_BUFFER_SIZE
21#define FTP_RESULT_BUFFER_SIZE 300
22#endif
23
24#ifndef FTP_COMMAND_PORT
25#define FTP_COMMAND_PORT 21
26#endif
27
28#ifndef FTP_MAX_SESSIONS
29#define FTP_MAX_SESSIONS 10
30#endif
31
32namespace ftp_client {
33
35enum FileMode { READ_MODE, WRITE_MODE, WRITE_APPEND_MODE };
36enum CurrentOperation { READ_OP, WRITE_OP, LS_OP, NOP, IS_EOF };
37enum LogLevel { LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR };
38enum ObjectType { TypeFile, TypeDirectory, TypeUndefined };
39
47 public:
48 static int findNthInStr(char *str, char ch, int n) {
49 int occur = 0;
50 // Loop to find the Nth
51 // occurence of the character
52 for (unsigned int i = 0; i < strlen(str); i++) {
53 if (str[i] == ch) {
54 occur += 1;
55 }
56 if (occur == n) return i;
57 }
58 return -1;
59 }
60
61 static int readln(Stream &stream, char *str, int maxLen) {
62 int len = 0;
63 if (maxLen > stream.available()) {
64 maxLen = stream.available();
65 }
66 for (int j = 0; j < maxLen; j++) {
67 len = j;
68 char c = stream.read();
69 if (c == 0 || c == '\n') {
70 break;
71 }
72 str[j] = c;
73 }
74 // For Windows we remove the \r at the end
75 if (str[len - 1] == '\r') {
76 len--; // remove \r
77 }
78 memset(str + len, 0, maxLen - len);
79 return len;
80 }
81};
82
83}
84
85#if FTP_USE_NAMESPACE
86using namespace ftp_client;
87#endif
CStringFunctions We implemented some missing C based string functions for character arrays.
Definition FTPCommon.h:46