/// <summary> /// /// </summary> /// <param name="clientInfo"></param> /// <returns></returns> public List <FileStruct> receiveFileList(ClientInfo clientInfo) { IOStream ioStream = clientInfo.IoStream; List <FileStruct> fileList = new List <FileStruct>(); if (showFileListProgress()) { startFileListProgress("receiving file list"); } Int64 startRead = Options.stats.totalRead; UInt32 flags; while ((flags = ioStream.readByte()) != 0) { if (options.protocolVersion >= 28 && (flags & Options.XMIT_EXTENDED_FLAGS) != 0) { flags |= (UInt32)(ioStream.readByte() << 8); } FileStruct file = receiveFileEntry(flags, clientInfo); if (file == null) { continue; } fileList.Add(file); Options.stats.totalSize += (fileList[fileList.Count - 1]).length; EmitFileListProgress(fileList); if (options.verbose > 2) { Log.WriteLine("receiveFileName(" + (fileList[fileList.Count - 1]).GetFullName() + ")"); } } receiveFileEntry(0, null); if (options.verbose > 2) { Log.WriteLine("received " + fileList.Count + " names"); } if (showFileListProgress()) { finishFileListProgress(fileList); } cleanFileList(fileList, options.relativePaths, true); if (ioStream != null) { ioStream.readInt(); } if (options.verbose > 3) { outputFileList(fileList); } if (options.listOnly) { logFileList(fileList); } if (options.verbose > 2) { Log.WriteLine("receiveFileList done"); } Options.stats.fileListSize = (int)(Options.stats.totalRead - startRead); Options.stats.numFiles = fileList.Count; return(fileList); }
public FileStruct receiveFileEntry(UInt32 flags, ClientInfo clientInfo) { if (clientInfo == null) { lastName = String.Empty; return(null); } IOStream f = clientInfo.IoStream; int l1 = 0, l2 = 0; if ((flags & Options.XMIT_SAME_NAME) != 0) { l1 = f.readByte(); } if ((flags & Options.XMIT_LONG_NAME) != 0) { l2 = f.readInt(); } else { l2 = f.readByte(); } if (l2 >= Options.MAXPATHLEN - l1) { MainClass.Exit("overflow: lastname=" + lastName, clientInfo); } string thisName = lastName.Substring(0, l1); thisName += f.ReadStringFromBuffer(l2); lastName = thisName; thisName = Util.cleanFileName(thisName, false); if (options.sanitizePath) { thisName = Util.sanitizePath(thisName, String.Empty, 0); } string baseName = String.Empty; string dirName = String.Empty; if (thisName.LastIndexOf("/") != -1) { baseName = Path.GetFileName(thisName); dirName = Path.GetDirectoryName(thisName); } else { baseName = thisName; dirName = null; } Int64 fileLength = f.ReadLongInt(); if ((flags & Options.XMIT_SAME_TIME) == 0) { modTime = DateTime.FromFileTime(f.readInt()); } if ((flags & Options.XMIT_SAME_MODE) == 0) { mode = (UInt32)f.readInt(); } if (options.preserveUID && (flags & Options.XMIT_SAME_UID) == 0) { int uid = f.readInt(); } if (options.preserveGID && (flags & Options.XMIT_SAME_GID) == 0) { int gid = f.readInt(); } byte[] sum = new byte[0]; if (options.alwaysChecksum && !Util.S_ISDIR(mode)) { sum = new byte[CheckSum.MD4_SUM_LENGTH]; sum = f.ReadBuffer(options.protocolVersion < 21 ? 2 : CheckSum.MD4_SUM_LENGTH); } FileStruct fs = new FileStruct(); fs.length = (int)fileLength; fs.baseName = baseName; fs.dirName = dirName; fs.sum = sum; fs.mode = mode; fs.modTime = modTime; fs.flags = flags; return(fs); }
public ArrayList receiveFileList(ClientInfo cInfo) { IOStream f = cInfo.IoStream; ArrayList fileList = new ArrayList(); if (showFileListP()) { startFileListProgress("receiving file list"); } Int64 startRead = Options.stats.totalRead; UInt32 flags; while ((flags = f.readByte()) != 0) { if (options.protocolVersion >= 28 && (flags & Options.XMIT_EXTENDED_FLAGS) != 0) { flags |= (UInt32)(f.readByte() << 8); } FileStruct file = receiveFileEntry(flags, cInfo); if (file == null) { continue; } fileList.Add(file); Options.stats.totalSize += ((FileStruct)fileList[fileList.Count - 1]).length; mayBeEmitFileListProgress(fileList); if (options.verbose > 2) { Log.WriteLine("receiveFileName(" + ((FileStruct)fileList[fileList.Count - 1]).FNameTo() + ")"); } } receiveFileEntry(0, null); if (options.verbose > 2) { Log.WriteLine("received " + fileList.Count + " names"); } if (showFileListP()) { finishFileListProgress(fileList); } cleanFileList(fileList, (options.relativePaths == 0) ? false : true, true); if (f != null) { f.readInt(); } if (options.verbose > 3) { outputFileList(fileList); } if (options.listOnly) { for (int i = 0; i < fileList.Count; i++) { listFileEntry((FileStruct)fileList[i]); } } if (options.verbose > 2) { Log.WriteLine("receiveFileList done"); } Options.stats.flistSize = (int)(Options.stats.totalRead - startRead); Options.stats.numFiles = fileList.Count; return(fileList); }