Changeset 82841 in vbox for trunk/src/VBox
- Timestamp:
- Jan 23, 2020 10:02:26 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/tools/RTFTPServer.cpp
r82822 r82841 69 69 typedef struct FTPSERVERDATA 70 70 { 71 char szRootDir[RTPATH_MAX]; 71 /** The absolute path of the FTP server's root directory. */ 72 char szPathRootAbs[RTPATH_MAX]; 73 /** The relative current working directory (CWD) to szRootDir. */ 72 74 char szCWD[RTPATH_MAX]; 73 75 RTFILE hFile; … … 241 243 static DECLCALLBACK(int) onFileGetSize(PRTFTPCALLBACKDATA pData, const char *pcszPath, uint64_t *puSize) 242 244 { 243 RT_NOREF(pData); 245 PFTPSERVERDATA pThis = (PFTPSERVERDATA)pData->pvUser; 246 Assert(pData->cbUser == sizeof(FTPSERVERDATA)); 247 248 char *pszStat = NULL; 249 if (RTStrAPrintf(&pszStat, "%s/%s", pThis->szPathRootAbs, pcszPath) <= 0) 250 return VERR_NO_MEMORY; 244 251 245 252 RTPrintf("Retrieving file size for '%s' ...\n", pcszPath); … … 256 263 } 257 264 265 RTStrFree(pszStat); 266 258 267 return rc; 259 268 } … … 264 273 Assert(pData->cbUser == sizeof(FTPSERVERDATA)); 265 274 266 const char *pcszStat = pcszPath ? pcszPath : pThis->szCWD; 267 268 RTPrintf("Stat for '%s'\n", pcszStat); 275 char *pszStat = NULL; 276 if (RTStrAPrintf(&pszStat, "%s/%s", pThis->szPathRootAbs, pcszPath) <= 0) 277 return VERR_NO_MEMORY; 278 279 RTPrintf("Stat for '%s'\n", pszStat); 269 280 270 281 RTFILE hFile; 271 int rc = RTFileOpen(&hFile, p cszStat,282 int rc = RTFileOpen(&hFile, pszStat, 272 283 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE); 273 284 if (RT_SUCCESS(rc)) … … 284 295 } 285 296 297 RTStrFree(pszStat); 298 286 299 return rc; 287 300 } … … 327 340 /* Construct absolute path. */ 328 341 char *pszPathAbs = NULL; 329 int rc = RTStrAAppend(&pszPathAbs, pThis->szRootDir); 330 AssertRCReturn(rc, rc); 331 rc = RTStrAAppend(&pszPathAbs, pcszPath); 332 AssertRCReturn(rc, rc); 342 if (RTStrAPrintf(&pszPathAbs, "%s/%s", pThis->szPathRootAbs, pcszPath) <= 0) 343 return VERR_NO_MEMORY; 333 344 334 345 RTPrintf("Opening directory '%s'\n", pszPathAbs); 335 346 336 rc = RTVfsChainOpenDir(pszPathAbs, 0 /*fFlags*/, &pHandle->hVfsDir, NULL /* poffError */, NULL /* pErrInfo */);347 int rc = RTVfsChainOpenDir(pszPathAbs, 0 /*fFlags*/, &pHandle->hVfsDir, NULL /* poffError */, NULL /* pErrInfo */); 337 348 if (RT_SUCCESS(rc)) 338 349 { … … 489 500 490 501 case 'r': 491 RTStrCopy(g_FTPServerData.sz RootDir, sizeof(g_FTPServerData.szRootDir), ValueUnion.psz);502 RTStrCopy(g_FTPServerData.szPathRootAbs, sizeof(g_FTPServerData.szPathRootAbs), ValueUnion.psz); 492 503 break; 493 504 … … 524 535 } 525 536 526 if (!strlen(g_FTPServerData.sz RootDir))537 if (!strlen(g_FTPServerData.szPathRootAbs)) 527 538 { 528 539 /* By default use the current directory as serving root directory. */ 529 rc = RTPathGetCurrent(g_FTPServerData.sz RootDir, sizeof(g_FTPServerData.szRootDir));540 rc = RTPathGetCurrent(g_FTPServerData.szPathRootAbs, sizeof(g_FTPServerData.szPathRootAbs)); 530 541 if (RT_FAILURE(rc)) 531 542 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Retrieving current directory failed: %Rrc", rc); … … 566 577 { 567 578 RTPrintf("Starting FTP server at %s:%RU16 ...\n", szAddress, uPort); 568 RTPrintf("Root directory is '%s'\n", g_FTPServerData.sz RootDir);579 RTPrintf("Root directory is '%s'\n", g_FTPServerData.szPathRootAbs); 569 580 570 581 RTPrintf("Running FTP server ...\n");
Note:
See TracChangeset
for help on using the changeset viewer.