Changeset 82687 in vbox for trunk/src/VBox/Runtime/tools
- Timestamp:
- Jan 9, 2020 10:45:36 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 135606
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/tools/RTFTPServer.cpp
r82671 r82687 57 57 *********************************************************************************************************************************/ 58 58 /** Set by the signal handler when the FTP server shall be terminated. */ 59 static volatile bool g_fCanceled = false; 59 static volatile bool g_fCanceled = false; 60 static char *g_pszRootDir = NULL; 60 61 61 62 … … 145 146 } 146 147 148 static DECLCALLBACK(int) onUserConnect(PRTFTPCALLBACKDATA pData, const char *pcszUser) 149 { 150 RT_NOREF(pData, pcszUser); 151 152 RTPrintf("User '%s' connected", pcszUser); 153 154 return VINF_SUCCESS; 155 } 156 157 static DECLCALLBACK(int) onUserAuthenticate(PRTFTPCALLBACKDATA pData, const char *pcszUser, const char *pcszPassword) 158 { 159 RT_NOREF(pData, pcszUser, pcszPassword); 160 161 RTPrintf("Authenticating user '%s' ...", pcszUser); 162 163 return VINF_SUCCESS; 164 } 165 166 static DECLCALLBACK(int) onUserDisonnect(PRTFTPCALLBACKDATA pData) 167 { 168 RT_NOREF(pData); 169 170 RTPrintf("User disconnected"); 171 172 return VINF_SUCCESS; 173 } 174 175 static DECLCALLBACK(int) onPathSetCurrent(PRTFTPCALLBACKDATA pData, const char *pcszCWD) 176 { 177 RT_NOREF(pData, pcszCWD); 178 179 RTPrintf("Setting current directory to '%s'\n", pcszCWD); 180 181 return VINF_SUCCESS; 182 } 183 184 static DECLCALLBACK(int) onPathGetCurrent(PRTFTPCALLBACKDATA pData, char *pszPWD, size_t cbPWD) 185 { 186 RT_NOREF(pData, pszPWD, cbPWD); 187 188 return VINF_SUCCESS; 189 } 190 191 static DECLCALLBACK(int) onList(PRTFTPCALLBACKDATA pData, void **ppvData, size_t *pcbData) 192 { 193 RT_NOREF(pData, ppvData, pcbData); 194 195 return VINF_SUCCESS; 196 } 197 147 198 int main(int argc, char **argv) 148 199 { … … 154 205 char szAddress[64] = "localhost"; 155 206 uint16_t uPort = 2121; 156 157 /* By default use the current directory as serving root directory. */158 char szRootDir[RTPATH_MAX];159 rc = RTPathGetCurrent(szRootDir, sizeof(szRootDir));160 if (RT_FAILURE(rc))161 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Retrieving current directory failed: %Rrc", rc);162 207 163 208 /* … … 190 235 case 'p': 191 236 uPort = ValueUnion.u16; 237 break; 238 239 case 'r': 240 g_pszRootDir = RTStrDup(ValueUnion.psz); 192 241 break; 193 242 … … 224 273 } 225 274 275 if (!g_pszRootDir) 276 { 277 char szRootDir[RTPATH_MAX]; 278 279 /* By default use the current directory as serving root directory. */ 280 rc = RTPathGetCurrent(szRootDir, sizeof(szRootDir)); 281 if (RT_FAILURE(rc)) 282 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Retrieving current directory failed: %Rrc", rc); 283 284 g_pszRootDir = RTStrDup(szRootDir); 285 if (!g_pszRootDir) 286 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Allocating current directory failed"); 287 } 288 226 289 /* Install signal handler. */ 227 290 rc = signalHandlerInstall(); … … 231 294 * Create the FTP server instance. 232 295 */ 296 RTFTPSERVERCALLBACKS Callbacks; 297 RT_ZERO(Callbacks); 298 Callbacks.pfnOnUserConnect = onUserConnect; 299 Callbacks.pfnOnUserAuthenticate = onUserAuthenticate; 300 Callbacks.pfnOnUserDisconnect = onUserDisonnect; 301 Callbacks.pfnOnPathSetCurrent = onPathSetCurrent; 302 Callbacks.pfnOnPathGetCurrent = onPathGetCurrent; 303 Callbacks.pfnOnList = onList; 304 233 305 RTFTPSERVER hFTPServer; 234 rc = RTFTPServerCreate(&hFTPServer, szAddress, uPort, szRootDir);306 rc = RTFTPServerCreate(&hFTPServer, szAddress, uPort, &Callbacks); 235 307 if (RT_SUCCESS(rc)) 236 308 { 237 309 RTPrintf("Starting FTP server at %s:%RU16 ...\n", szAddress, uPort); 238 RTPrintf("Root directory is '%s'\n", szRootDir);310 RTPrintf("Root directory is '%s'\n", g_pszRootDir); 239 311 240 312 RTPrintf("Running FTP server ...\n"); … … 264 336 } 265 337 338 RTStrFree(g_pszRootDir); 339 266 340 /* Set rcExit on failure in case we forgot to do so before. */ 267 341 if (RT_FAILURE(rc))
Note:
See TracChangeset
for help on using the changeset viewer.