bstring splitPath(bstring & path, bstring const & filePath) { size_t i = filePath.find_last_of('/'); if (i == (size_t)-1) { path = TEXT("/"); return filePath; } ++i; path = filePath.substr(0, i); return filePath.substr(i); }
//--------------------------------------------------------------------- // put a local file --> remote bool Server::cmdPut(bstring const & localName, bstring const & remotePath, bool exists) { DBGPRINT(("put '%s' '%s' %b\r\n", localName.c_str(), remotePath.c_str(), exists)); bstring cmd = bstring(exists ? TEXT("reput \"") : TEXT("put \"")) + localName + TEXT("\" \"") + remotePath + TEXT("\""); if (!doCommand(cmd)) return false; FILETIME ft; HANDLE hFile = CreateFile(localName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile == (HANDLE)HFILE_ERROR) return true; // copy succeeded GetFileTime(hFile, 0, 0, &ft); long fsHigh = 0; long fsLow = SetFilePointer(hFile, 0, &fsHigh, FILE_END); CloseHandle(hFile); bstring chmod = TEXT("----"); if (defChMod.length() > 0 || exeChMod.length() > 0) { chmod = defChMod; size_t ldot = remotePath.find_last_of('.'); if (ldot != (size_t)-1) { bstring x = remotePath.substr(ldot); std::map<bstring, bstring>::iterator i = exeExtensions.find(x); if (i != exeExtensions.end()) chmod = exeChMod; } if (chmod.length() > 0) { cmd = bstring(TEXT("chmod ")) + chmod + TEXT(" \"") + remotePath + TEXT("\""); doCommand(cmd); } } // fake update the directory insertFile(remotePath, &ft, fsLow, fsHigh, '-', chmod); // we cannot set the file time if (disableMtime) return true; // if setting the mtime failes, do not try it again if (!this->cmdMtime(remotePath, &ft)) disableMtime = true; // put already succeeded. return true; }
bool doTransferAscii(bstring const & filename) { WLock wlock; if (transferAscii) return true; if (modeExtensions.size() == 0) return false; // check the extension size_t dot = filename.find_last_of('.'); if (dot == (size_t)-1) return false; bstring ext = filename.substr(dot); std::map<bstring, bstring>::iterator i = modeExtensions.find(ext); return i != modeExtensions.end(); }