コード例 #1
0
        public bool PutFile(IPurePath sourcePath, IPurePath destinationPath, IFileTransferHandler handler, bool ifNewer)
        {
            var filename = sourcePath.Filename;
            var source = Context.LocalEnv.CurrentDirectory.Join(sourcePath);
            var dest = Context.LocalEnv.CurrentDirectory.Join(destinationPath);

            if (handler != null)
            {
                handler.Filename = filename;
            }

            if (!File.Exists(source.ToString()))
            {
                if (handler != null)
                {
                    handler.FileDoesNotExist();
                }
                return false;
            }

            if (String.IsNullOrEmpty(dest.Filename) ||
                Directory.Exists(dest.ToString()))
            {
                dest = dest.WithFilename(filename);
            }

            var sourceStr = source.ToString();
            var destStr = dest.ToString();

            if (ifNewer && File.Exists(destStr) &&
                File.GetLastWriteTimeUtc(sourceStr) <= File.GetLastWriteTimeUtc(destStr))
            {
                if (handler != null)
                {
                    handler.FileUpToDate();
                }
                return false;
            }
            using (var file = File.OpenRead(sourceStr))
            {

                PutFile(file, destStr, handler);
            }
            return true;
        }
コード例 #2
0
        public bool PutFile(IPurePath sourcePath, IPurePath destinationPath, IFileTransferHandler handler, bool ifNewer)
        {
            var filename = sourcePath.Filename;
            var source = Context.LocalEnv.CurrentDirectory.Join(sourcePath);
            var dest = Context.RemoteEnv.CurrentDirectory.Join(destinationPath);

            if (handler != null)
            {
                handler.Filename = filename;
            }

            if (!File.Exists(source.ToString()))
            {
                if (handler != null)
                {
                    handler.FileDoesNotExist();
                }
                return false;
            }

            if (String.IsNullOrEmpty(dest.Filename) ||
                Sftp.GetAttributes(dest.ToString()).IsDirectory)
            {
                dest = dest.WithFilename(filename);
            }

            if (ifNewer)
            {
                var modified = File.GetLastWriteTimeUtc(source.ToString());
                var remoteModified = DateTime.MinValue;
                try
                {
                    remoteModified = Sftp.GetLastWriteTimeUtc(dest.ToString());
                }
                catch (SftpPathNotFoundException)
                {
                }
                if (modified <= remoteModified)
                {
                    if (handler != null)
                    {
                        handler.FileUpToDate();
                    }
                    return false;
                }
            }
            using (var file = File.OpenRead(source.ToString()))
            {
                PutFile(file, dest, handler);
            }
            return true;
        }