Exemple #1
0
        /* Perform our quick-check heuristic for determining if a file is unchanged. */
        public bool UnchangedFile(string fileName, FileStruct file)
        {
            // TODO: path length
            if (!FileSystem.File.Exists(fileName))
            {
                return(false);
            }

            FileSystem.FileInfo fi = new FileSystem.FileInfo(fileName);
            // TODO: path length
            if (fi.Length != file.length)
            {
                return(false);
            }

            /* if always checksum is set then we use the checksum instead
             * of the file time to determine whether to sync */
            if (options.alwaysChecksum)
            {
                byte[] sum = new byte[CheckSum.MD4_SUM_LENGTH];
                // TODO: path length
                checkSum.FileCheckSum(fileName, ref sum, (int)fi.Length);
                return(Util.MemCmp(sum, 0, file.sum, 0, options.protocolVersion < 21 ? 2 : CheckSum.MD4_SUM_LENGTH) == 0);
            }

            if (options.sizeOnly)
            {
                return(true);
            }

            if (options.ignoreTimes)
            {
                return(false);
            }

            // TODO: path length
            return(Util.CompareModTime(fi.LastWriteTime.Second, file.modTime.Second, options) == 0);
        }
Exemple #2
0
        public void SendFiles(ArrayList fileList, ClientInfo cInfo)
        {
            ShowMessage("Processing...");
            try
            {
                IOStream  f = cInfo.IoStream;
                string    fileName = "", fileName2 = "";
                SumStruct s               = null;
                int       phase           = 0;
                bool      saveMakeBackups = options.makeBackups;
                Match     match           = new Match(options);

                if (options.verbose > 2)
                {
                    Log.WriteLine("SendFiles starting");
                }
                while (true)
                {
                    fileName = "";
                    int i = f.readInt();
                    if (i == -1)
                    {
                        if (phase == 0)
                        {
                            phase++;
                            checkSum.cSumLength = CheckSum.SUM_LENGTH;
                            f.writeInt(-1);
                            if (options.verbose > 2)
                            {
                                Log.WriteLine("SendFiles phase=" + phase);
                            }
                            options.makeBackups = false;
                            continue;
                        }
                        break;
                    }

                    if (i < 0 || i >= fileList.Count)
                    {
                        MainClass.Exit("Invalid file index " + i + " (count=" + fileList.Count + ")", cInfo);
                    }

                    FileStruct file = (FileStruct)fileList[i];

                    Options.stats.currentFileIndex = i;
                    Options.stats.numTransferredFiles++;
                    Options.stats.totalTransferredSize += file.length;

                    if (file.baseDir != null && file.baseDir.CompareTo("") != 0)
                    {
                        fileName = file.baseDir;
                        if (!fileName.EndsWith("/"))
                        {
                            fileName += "/";
                        }
                    }
                    fileName2 = file.FNameTo();
                    fileName += file.FNameTo();
                    ShowMessage("uploading " + fileName);

                    if (options.verbose > 2)
                    {
                        Log.WriteLine("sendFiles(" + i + ", " + fileName + ")");
                    }

                    if (options.dryRun)
                    {
                        if (!options.amServer && options.verbose != 0)
                        {
                            Log.WriteLine(fileName2);
                        }
                        f.writeInt(i);
                        continue;
                    }

                    Stats initialStats = Options.stats;
                    s = ReceiveSums(cInfo);

                    Stream fd;
                    try
                    {
                        fd = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                    }
                    catch (FileNotFoundException)
                    {
                        Log.WriteLine("file has vanished: " + Util.fullFileName(fileName));
                        s = null;
                        continue;
                    }
                    catch (Exception)
                    {
                        Log.WriteLine("SendFiles failed to open " + Util.fullFileName(fileName));
                        s = null;
                        continue;
                    }

                    FStat st = new FStat();
                    FileSystem.FileInfo fi = new FileSystem.FileInfo(fileName);
                    // TODO: path length
                    st.mTime = fi.LastWriteTime;
                    // TODO: path length
                    st.size = fi.Length;

                    MapFile mbuf = null;
                    if (st.size != 0)
                    {
                        int mapSize = (int)Math.Max(s.bLength * 3, Options.MAX_MAP_SIZE);
                        mbuf = new MapFile(fd, (int)st.size, mapSize, (int)s.bLength);
                    }

                    if (options.verbose > 2)
                    {
                        Log.WriteLine("SendFiles mapped " + fileName + " of size " + st.size);
                    }

                    f.writeInt(i);
                    Generator gen = new Generator(options);
                    gen.WriteSumHead(f, s);

                    if (options.verbose > 2)
                    {
                        Log.WriteLine("calling MatchSums " + fileName);
                    }

                    if (!options.amServer && options.verbose != 0)
                    {
                        Log.WriteLine(fileName2);
                    }

                    Token token = new Token(options);
                    token.SetCompression(fileName);

                    match.MatchSums(f, s, mbuf, (int)st.size);
                    Log.LogSend(file, initialStats);

                    if (mbuf != null)
                    {
                        bool j = mbuf.UnMapFile();
                        if (j)
                        {
                            Log.WriteLine("read errors mapping " + Util.fullFileName(fileName));
                        }
                    }
                    fd.Close();

                    s.sums = null;

                    if (options.verbose > 2)
                    {
                        Log.WriteLine("sender finished " + fileName);
                    }
                }
                options.makeBackups = saveMakeBackups;

                if (options.verbose > 2)
                {
                    Log.WriteLine("send files finished");
                }

                match.MatchReport(f);
                f.writeInt(-1);
            }
            finally
            {
                HideMessage();
            }
        }
Exemple #3
0
		public FileStruct makeFile(string fileName, ArrayList fileList, int excludeLevel)
		{
			if(fileName == null || fileName.CompareTo("") == 0) return null;
			string thisName = Util.cleanFileName(fileName,false);
			if(options.sanitizePath)
				thisName = Util.sanitizePath(thisName, "", 0);
			FileStruct fs = new FileStruct();
			// TODO: path length
			if(FileSystem.Directory.Exists(thisName))
			{									
				if(thisName.LastIndexOf('/') != -1)
				{
					thisName = thisName.TrimEnd('/');
					fs.dirName = thisName.Substring(0,thisName.LastIndexOf('/')).Replace(@"\","/");
					fs.baseName = thisName.Substring(thisName.LastIndexOf('/') + 1);				
					fs.gid = 0;
					fs.uid = 0;
					fs.mode = 0x4000 | 0x16B ;
					// TODO: path length
					FileSystem.DirectoryInfo di = new FileSystem.DirectoryInfo(thisName);
					if((di.Attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
						fs.mode |= 0x92;
				}

			}
			// TODO: path length
			if(FileSystem.File.Exists(thisName))
			{
				
				if (excludeLevel != Options.NO_EXCLUDES && checkExcludeFile(thisName, 0, excludeLevel))
					return null;				
				fs.baseName = Path.GetFileName(thisName);
				fs.dirName = FileSystem.Directory.GetDirectoryName(thisName).Replace(@"\","/").TrimEnd('/');				
				FileSystem.FileInfo fi = new FileSystem.FileInfo(thisName);
				
				// TODO: path length
				fs.length = (int)fi.Length;
				// TODO: path length
				fs.modTime = fi.LastWriteTime;	
				fs.mode = 0x8000 | 0x1A4 ; 
				// TODO: path length
				if((FileSystem.File.GetAttributes(thisName) & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
				   fs.mode |= 0x92;
				fs.gid = 0;
				fs.uid = 0;
				
				int sum_len = options.alwaysChecksum ? CheckSum.MD4_SUM_LENGTH : 0;				
				if(sum_len != 0)
					if(!checkSum.FileCheckSum(thisName, ref fs.sum, fs.length))
					{
						Log.Write("Skipping file " + thisName);
						return null;
					}

				Options.stats.totalSize += fs.length;

			}
			fs.baseDir = fileListDir;			
			return fs;
		}
Exemple #4
0
        public FileStruct makeFile(string fileName, ArrayList fileList, int excludeLevel)
        {
            if (fileName == null || fileName.CompareTo("") == 0)
            {
                return(null);
            }
            string thisName = Util.cleanFileName(fileName, false);

            if (options.sanitizePath)
            {
                thisName = Util.sanitizePath(thisName, "", 0);
            }
            FileStruct fs = new FileStruct();

            // TODO: path length
            if (FileSystem.Directory.Exists(thisName))
            {
                if (thisName.LastIndexOf('/') != -1)
                {
                    thisName    = thisName.TrimEnd('/');
                    fs.dirName  = thisName.Substring(0, thisName.LastIndexOf('/')).Replace(@"\", "/");
                    fs.baseName = thisName.Substring(thisName.LastIndexOf('/') + 1);
                    fs.gid      = 0;
                    fs.uid      = 0;
                    fs.mode     = 0x4000 | 0x16B;
                    // TODO: path length
                    FileSystem.DirectoryInfo di = new FileSystem.DirectoryInfo(thisName);
                    if ((di.Attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
                    {
                        fs.mode |= 0x92;
                    }
                }
            }
            // TODO: path length
            if (FileSystem.File.Exists(thisName))
            {
                if (excludeLevel != Options.NO_EXCLUDES && checkExcludeFile(thisName, 0, excludeLevel))
                {
                    return(null);
                }
                fs.baseName = Path.GetFileName(thisName);
                fs.dirName  = FileSystem.Directory.GetDirectoryName(thisName).Replace(@"\", "/").TrimEnd('/');
                FileSystem.FileInfo fi = new FileSystem.FileInfo(thisName);

                // TODO: path length
                fs.length = (int)fi.Length;
                // TODO: path length
                fs.modTime = fi.LastWriteTime;
                fs.mode    = 0x8000 | 0x1A4;
                // TODO: path length
                if ((FileSystem.File.GetAttributes(thisName) & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
                {
                    fs.mode |= 0x92;
                }
                fs.gid = 0;
                fs.uid = 0;

                int sum_len = options.alwaysChecksum ? CheckSum.MD4_SUM_LENGTH : 0;
                if (sum_len != 0)
                {
                    if (!checkSum.FileCheckSum(thisName, ref fs.sum, fs.length))
                    {
                        Log.Write("Skipping file " + thisName);
                        return(null);
                    }
                }

                Options.stats.totalSize += fs.length;
            }
            fs.baseDir = fileListDir;
            return(fs);
        }
Exemple #5
0
		public void SendFiles(ArrayList fileList, ClientInfo cInfo)
		{
			ShowMessage("Processing...");
			try 
			{
				IOStream f = cInfo.IoStream;
				string fileName = "", fileName2 = "";
				SumStruct s = null;
				int phase = 0;
				bool saveMakeBackups = options.makeBackups;			
				Match match = new Match(options);

				if( options.verbose > 2)
					Log.WriteLine("SendFiles starting");			
				while (true)
				{
					fileName = "";				
					int i = f.readInt();
					if (i == -1) 
					{
						if (phase == 0) 
						{
							phase++;
							checkSum.cSumLength = CheckSum.SUM_LENGTH;
							f.writeInt(-1);
							if (options.verbose > 2)
								Log.WriteLine("SendFiles phase=" + phase);
							options.makeBackups = false;																	
							continue;
						}
						break;
					}

					if (i < 0 || i >= fileList.Count) 
					{										
						MainClass.Exit("Invalid file index " + i + " (count=" + fileList.Count + ")",cInfo);
					}

					FileStruct file = (FileStruct)fileList[i];

					Options.stats.currentFileIndex = i;
					Options.stats.numTransferredFiles++;
					Options.stats.totalTransferredSize += file.length;

					if (file.baseDir != null && file.baseDir.CompareTo("") != 0) 
					{
						fileName = file.baseDir;
						if(!fileName.EndsWith("/"))
							fileName += "/";
					} 
					fileName2 = file.FNameTo();
					fileName +=  file.FNameTo();
					ShowMessage("uploading " + fileName);

					if (options.verbose > 2)
						Log.WriteLine("sendFiles(" + i + ", " + fileName + ")");

					if (options.dryRun) 
					{
						if (!options.amServer && options.verbose != 0)
							Log.WriteLine(fileName2);
						f.writeInt(i);
						continue;
					}

					Stats initialStats = Options.stats;
					s = ReceiveSums(cInfo);

					Stream fd;
					try
					{
						fd = new FileStream(fileName, FileMode.Open, FileAccess.Read);
					}
					catch(FileNotFoundException)
					{				
						Log.WriteLine("file has vanished: " + Util.fullFileName(fileName));
						s = null;
						continue;
					}
					catch(Exception)
					{					
						Log.WriteLine("SendFiles failed to open " + Util.fullFileName(fileName));
						s = null;
						continue;
					}

					FStat st = new FStat();
					FileSystem.FileInfo fi = new FileSystem.FileInfo(fileName);
					// TODO: path length
					st.mTime = fi.LastWriteTime;
					// TODO: path length
					st.size = fi.Length;

					MapFile mbuf = null;
					if (st.size != 0) 
					{
						int mapSize = (int)Math.Max(s.bLength * 3, Options.MAX_MAP_SIZE);
						mbuf = new MapFile(fd, (int)st.size, mapSize, (int)s.bLength);
					} 

					if (options.verbose > 2) 
						Log.WriteLine("SendFiles mapped " + fileName + " of size " + st.size);

					f.writeInt(i);
					Generator gen = new Generator(options);
					gen.WriteSumHead(f, s);

					if (options.verbose > 2) 
						Log.WriteLine("calling MatchSums " + fileName);

					if (!options.amServer && options.verbose != 0)
						Log.WriteLine(fileName2);

					Token token = new Token(options);
					token.SetCompression(fileName);

					match.MatchSums(f, s, mbuf, (int)st.size);
					Log.LogSend(file, initialStats);

					if (mbuf != null) 
					{
						bool j = mbuf.UnMapFile();
						if (j) 
						{						
							Log.WriteLine("read errors mapping " + Util.fullFileName(fileName));
						}
					}
					fd.Close();

					s.sums = null;

					if (options.verbose > 2) 
						Log.WriteLine("sender finished " + fileName);
				}
				options.makeBackups = saveMakeBackups;

				if (options.verbose > 2)
					Log.WriteLine("send files finished");

				match.MatchReport(f);
				f.writeInt(-1);			
			}
			finally
			{
				HideMessage();
			}
		}
Exemple #6
0
		public int ReceiveFiles(ClientInfo cInfo, ArrayList fileList, string localName)
		{
			FStat st = new FStat();
			FileStruct file;
			IOStream f = cInfo.IoStream;
			
			string fileName;
			string fNameCmp = "", fNameTmp = "";		
			bool saveMakeBackups = options.makeBackups;
			int i, phase = 0;
			bool recv_ok;

			if (options.verbose > 2)
				Log.WriteLine("ReceiveFiles(" + fileList.Count + ") starting");		
			while (true) 
			{
				i = f.readInt();
				if (i == -1) {
					if (phase != 0)
						break;

					phase = 1;
					checkSum.cSumLength = CheckSum.SUM_LENGTH;
					if (options.verbose > 2)
						Log.WriteLine("ReceiveFiles phase=" + phase);
					f.writeInt(0); //send_msg DONE
					if (options.keepPartial)
						options.makeBackups = false;
					continue;
				}

				if (i < 0 || i >= fileList.Count) {				
					MainClass.Exit("Invalid file index " + i +" in receiveFiles (count=" + fileList.Count +")", cInfo);
				}

				file = ((FileStruct)fileList[i]);

				Options.stats.currentFileIndex = i;
				Options.stats.numTransferredFiles++;
				Options.stats.totalTransferredSize += file.length;			

				if (localName != null && localName.CompareTo("") != 0)
					fileName = localName;
				else
				{
					fileName = Path.Combine(options.dir,LocalizePath(cInfo, file.FNameTo().Replace(":","")).Replace("\\", "/"));
					//fileName = Path.Combine(options.dir, file.FNameTo().Replace(":","")).Replace("\\", "/");
					// TODO: path length
					FileSystem.Directory.CreateDirectory(Path.Combine(options.dir,LocalizePath(cInfo, file.dirName.Replace(":",""))).Replace("\\", "/"));
					Log.WriteLine(Path.Combine(options.dir, file.dirName));
					//FileSystem.Directory.CreateDirectory(Path.Combine(options.dir,file.dirName.Replace(":","")).Replace("\\", "/"));
				}

				if (options.dryRun) {
					if (!options.amServer && options.verbose > 0)
						Log.WriteLine(fileName);
					continue;
				}

				if (options.verbose > 2)
					Log.WriteLine("receiveFiles(" + fileName + ")");

				if (options.partialDir != null && options.partialDir.CompareTo("") != 0) {			
				} else
					fNameCmp = fileName;
				
				FileStream fd1 = null;
				try
				{
					fd1 = new FileStream(fNameCmp, FileMode.Open, FileAccess.Read);
				}
				catch(FileNotFoundException)
				{
					fNameCmp = fileName;
					try
					{
						fd1 = new FileStream(fNameCmp, FileMode.Open, FileAccess.Read);
					}
					catch(FileNotFoundException)
					{
					}
				}  catch(Exception e)
				{
					Log.Write(e.Message);
				}			
				try
				{
					FileSystem.FileInfo fi = new FileSystem.FileInfo(fNameCmp);
					// TODO: path length
					st.size = fi.Length;
				} 
				catch {}

				String tempFileName = getTmpName(fileName);
				FileStream fd2 = null;			
				fd2 = new FileStream(tempFileName,FileMode.OpenOrCreate,FileAccess.Write);				

				if (!options.amServer && options.verbose > 0)
					Log.WriteLine(fileName);

				/* recv file data */
				recv_ok = ReceiveData(cInfo, fNameCmp, fd1, st.size,
							fileName, fd2, file.length);

				if(fd1 != null)
					fd1.Close();
				if(fd2 != null)
					fd2.Close();
				// TODO: path length
				FileSystem.File.Copy(tempFileName, fileName, true);
				// TODO: path length
				FileSystem.File.Delete(tempFileName);
				if (recv_ok  || options.inplace)
					FinishTransfer(fileName, fNameTmp, file, recv_ok);
			}
			options.makeBackups = saveMakeBackups;

			if (options.deleteAfter && options.recurse && localName == null && fileList.Count > 0)
				DeleteFiles(fileList);

			if (options.verbose > 2)
				Log.WriteLine("ReceiveFiles finished");

			return 0;
		} 
Exemple #7
0
        public void ReceiveGenerator(string fileName, FileStruct file, int i, IOStream f)
        {
            fileName = Path.Combine(options.dir, fileName);

            if (UnchangedFile(fileName, file))
            {
                return;
            }
            if (options.verbose > 2)
            {
                Log.WriteLine("Receive Generator(" + fileName + "," + i + ")\n");
            }
            int   statRet;
            FStat st = new FStat();

            if (options.dryRun)
            {
                statRet = -1;
            }
            else
            {
                statRet = 0;
                try
                {
                    FileSystem.FileInfo fi = new FileSystem.FileInfo(fileName);
                    // TODO: path length
                    st.size = fi.Length;
                    // TODO: path length
                    st.mTime = fi.LastWriteTime;
                }
                catch
                {
                    statRet = -1;
                }
            }

            if (options.onlyExisting && statRet == -1)
            {
                /* we only want to update existing files */
                if (options.verbose > 1)
                {
                    Log.WriteLine("not creating new file \"" + fileName + "\"");
                }
                return;
            }
            string fNameCmp = fileName;

            if (options.wholeFile > 0)
            {
                f.writeInt(i);
                WriteSumHead(f, null);
                return;
            }
            FileStream fd;

            try
            {
                fd = new FileStream(fNameCmp, FileMode.Open, FileAccess.Read);
            }
            catch
            {
                if (options.verbose > 3)
                {
                    Log.WriteLine("failed to open " + Util.fullFileName(fNameCmp) + ", continuing");
                }
                f.writeInt(i);
                WriteSumHead(f, null);
                return;
            }

            if (options.verbose > 3)
            {
                Log.WriteLine("gen mapped " + fNameCmp + " of size " + st.size);
            }

            if (options.verbose > 2)
            {
                Log.WriteLine("generating and sending sums for " + i);
            }

            f.writeInt(i);
            Stream fCopy = null;

            GenerateAndSendSums(fd, st.size, f, fCopy);

            if (fCopy != null)
            {
                fCopy.Close();
            }
            fd.Close();
        }
Exemple #8
0
		public void ReceiveGenerator(string fileName, FileStruct file, int i, IOStream f)
		{		 		 
			fileName = Path.Combine(options.dir, fileName);		 

			if (UnchangedFile(fileName, file)) 
			{			 
				return;
			}
			if (options.verbose > 2)
				Log.WriteLine("Receive Generator(" + fileName + "," + i + ")\n"); 		 
			int statRet;
			FStat st = new FStat();
			if (options.dryRun) 
			{
				statRet = -1;		
			} 
			else 
			{
				statRet = 0;
				try
				{
					FileSystem.FileInfo fi = new FileSystem.FileInfo(fileName);
					// TODO: path length
					st.size = fi.Length;
					// TODO: path length
					st.mTime = fi.LastWriteTime;
				}
				catch
				{
					statRet = -1;
				}			 
			}

			if (options.onlyExisting && statRet == -1) 
			{
				/* we only want to update existing files */
				if (options.verbose > 1) 
					Log.WriteLine("not creating new file \"" + fileName + "\"");
				return;
			}
			string fNameCmp = fileName;
			if(options.wholeFile > 0)
			{
				f.writeInt(i);
				WriteSumHead(f, null);
				return;
			} 
			FileStream fd;
			try
			{
				fd = new FileStream(fNameCmp, FileMode.Open, FileAccess.Read);
			}
			catch
			{
				if (options.verbose > 3) 
					Log.WriteLine("failed to open " + Util.fullFileName(fNameCmp) + ", continuing");			 
				f.writeInt(i);
				WriteSumHead(f, null);
				return;
			}
				
			if (options.verbose > 3) 
				Log.WriteLine("gen mapped " + fNameCmp + " of size " + st.size);

			if (options.verbose > 2)
				Log.WriteLine("generating and sending sums for " + i);

			f.writeInt(i);
			Stream fCopy = null;
			GenerateAndSendSums(fd, st.size, f, fCopy);

			if (fCopy != null) 
			{
				fCopy.Close();			 
			}
			fd.Close(); 
		}
Exemple #9
0
		/* Perform our quick-check heuristic for determining if a file is unchanged. */
		public bool UnchangedFile(string fileName, FileStruct file)
		{			
			// TODO: path length
			if(!FileSystem.File.Exists(fileName))
				return false;
			
			FileSystem.FileInfo fi = new FileSystem.FileInfo(fileName);
			// TODO: path length
			if (fi.Length != file.length)
				return false;

			/* if always checksum is set then we use the checksum instead
			of the file time to determine whether to sync */
			if (options.alwaysChecksum) 
			{
				byte[] sum = new byte[CheckSum.MD4_SUM_LENGTH];
				// TODO: path length
				checkSum.FileCheckSum(fileName, ref sum, (int)fi.Length);
				return Util.MemCmp(sum, 0, file.sum, 0, options.protocolVersion < 21 ? 2 : CheckSum.MD4_SUM_LENGTH) == 0;
			}

			if (options.sizeOnly)
				return true;

			if (options.ignoreTimes)
				return false;

			// TODO: path length
			return Util.CompareModTime(fi.LastWriteTime.Second, file.modTime.Second, options) == 0;			
		}
Exemple #10
0
        public int ReceiveFiles(ClientInfo cInfo, ArrayList fileList, string localName)
        {
            FStat      st = new FStat();
            FileStruct file;
            IOStream   f = cInfo.IoStream;

            string fileName;
            string fNameCmp = "", fNameTmp = "";
            bool   saveMakeBackups = options.makeBackups;
            int    i, phase = 0;
            bool   recv_ok;

            if (options.verbose > 2)
            {
                Log.WriteLine("ReceiveFiles(" + fileList.Count + ") starting");
            }
            while (true)
            {
                i = f.readInt();
                if (i == -1)
                {
                    if (phase != 0)
                    {
                        break;
                    }

                    phase = 1;
                    checkSum.cSumLength = CheckSum.SUM_LENGTH;
                    if (options.verbose > 2)
                    {
                        Log.WriteLine("ReceiveFiles phase=" + phase);
                    }
                    f.writeInt(0);                     //send_msg DONE
                    if (options.keepPartial)
                    {
                        options.makeBackups = false;
                    }
                    continue;
                }

                if (i < 0 || i >= fileList.Count)
                {
                    MainClass.Exit("Invalid file index " + i + " in receiveFiles (count=" + fileList.Count + ")", cInfo);
                }

                file = ((FileStruct)fileList[i]);

                Options.stats.currentFileIndex = i;
                Options.stats.numTransferredFiles++;
                Options.stats.totalTransferredSize += file.length;

                if (localName != null && localName.CompareTo("") != 0)
                {
                    fileName = localName;
                }
                else
                {
                    fileName = Path.Combine(options.dir, LocalizePath(cInfo, file.FNameTo().Replace(":", "")).Replace("\\", "/"));
                    //fileName = Path.Combine(options.dir, file.FNameTo().Replace(":","")).Replace("\\", "/");
                    // TODO: path length
                    FileSystem.Directory.CreateDirectory(Path.Combine(options.dir, LocalizePath(cInfo, file.dirName.Replace(":", ""))).Replace("\\", "/"));
                    Log.WriteLine(Path.Combine(options.dir, file.dirName));
                    //FileSystem.Directory.CreateDirectory(Path.Combine(options.dir,file.dirName.Replace(":","")).Replace("\\", "/"));
                }

                if (options.dryRun)
                {
                    if (!options.amServer && options.verbose > 0)
                    {
                        Log.WriteLine(fileName);
                    }
                    continue;
                }

                if (options.verbose > 2)
                {
                    Log.WriteLine("receiveFiles(" + fileName + ")");
                }

                if (options.partialDir != null && options.partialDir.CompareTo("") != 0)
                {
                }
                else
                {
                    fNameCmp = fileName;
                }

                FileStream fd1 = null;
                try
                {
                    fd1 = new FileStream(fNameCmp, FileMode.Open, FileAccess.Read);
                }
                catch (FileNotFoundException)
                {
                    fNameCmp = fileName;
                    try
                    {
                        fd1 = new FileStream(fNameCmp, FileMode.Open, FileAccess.Read);
                    }
                    catch (FileNotFoundException)
                    {
                    }
                }  catch (Exception e)
                {
                    Log.Write(e.Message);
                }
                try
                {
                    FileSystem.FileInfo fi = new FileSystem.FileInfo(fNameCmp);
                    // TODO: path length
                    st.size = fi.Length;
                }
                catch {}

                String     tempFileName = getTmpName(fileName);
                FileStream fd2          = null;
                fd2 = new FileStream(tempFileName, FileMode.OpenOrCreate, FileAccess.Write);

                if (!options.amServer && options.verbose > 0)
                {
                    Log.WriteLine(fileName);
                }

                /* recv file data */
                recv_ok = ReceiveData(cInfo, fNameCmp, fd1, st.size,
                                      fileName, fd2, file.length);

                if (fd1 != null)
                {
                    fd1.Close();
                }
                if (fd2 != null)
                {
                    fd2.Close();
                }
                // TODO: path length
                FileSystem.File.Copy(tempFileName, fileName, true);
                // TODO: path length
                FileSystem.File.Delete(tempFileName);
                if (recv_ok || options.inplace)
                {
                    FinishTransfer(fileName, fNameTmp, file, recv_ok);
                }
            }
            options.makeBackups = saveMakeBackups;

            if (options.deleteAfter && options.recurse && localName == null && fileList.Count > 0)
            {
                DeleteFiles(fileList);
            }

            if (options.verbose > 2)
            {
                Log.WriteLine("ReceiveFiles finished");
            }

            return(0);
        }