Example #1
0
        private string _convertPath(string path)
        {
            //return GrfPath.Combine(DestPath, path.Replace(ProjectConfiguration.DatabasePath, "").TrimStart('/', '\\').Replace("/", "\\"));
            FtpUrlInfo url = new FtpUrlInfo(GrfPath.GetDirectoryName(ProjectConfiguration.DatabasePath));

            return(path.Replace(GrfPath.GetDirectoryName(ProjectConfiguration.DatabasePath), "").TrimStart('/', '\\').Replace(url.Path.TrimStart('/', '\\'), "").TrimStart('/', '\\'));
        }
Example #2
0
        public override bool Exists(string path)
        {
            _map();

            try {
                return(_entries.ContainsKey(_convertPath(path).Replace("\\", "/")));
            }
            catch {
                FtpUrlInfo url = new FtpUrlInfo(path);
                return(_entries.ContainsKey(url.Path.Replace("\\", "/")));
            }
        }
Example #3
0
        public override byte[] ReadAllBytes(string path)
        {
            var temp = _getTempPath();

            FtpUrlInfo urlSource = new FtpUrlInfo(path);
            var        entry     = _entries[urlSource.Path];

            if (_db.Exists(urlSource.Path, entry))
            {
                return(_db.Get(urlSource.Path));
            }

            DbDebugHelper.OnSftpUpdate("downloading " + urlSource.Path);
            _sftp.Get(urlSource.Path, temp);
            DbDebugHelper.OnSftpUpdate("caching " + urlSource.Path);
            _db.Set(temp, urlSource.Path, entry);

            return(File.ReadAllBytes(temp));
        }
Example #4
0
        public static FileManager Get(string path)
        {
            FtpUrlInfo info = new FtpUrlInfo(path);

            if (info.Scheme == "sftp")
            {
                return(new SftpFileManager(path));
            }
            if (info.Scheme == "ftp")
            {
                throw new Exception("Unsupported protocol (yes, FTP isn't supported, yet).");
                //return new FtpFileManager(path);
                //return new SftpFileManager(path);
            }
            if (info.Scheme == "file")
            {
                return(new SystemFileManager(path));
            }

            return(new SystemFileManager(path));
        }
Example #5
0
        public override void Copy(string sourceFile, string destFile)
        {
            _map();
            FtpUrlInfo urlSource = new FtpUrlInfo(sourceFile);
            FtpUrlInfo urlDest   = new FtpUrlInfo(destFile);

            if (urlSource.Scheme == "sftp")
            {
                var entry = _entries[urlSource.Path];

                if (_db.Exists(urlSource.Path, entry))
                {
                    var data = _db.Get(urlSource.Path);
                    File.WriteAllBytes(destFile, data);
                }
                else
                {
                    DbDebugHelper.OnSftpUpdate("downloading " + urlSource.Path);
                    _sftp.Get(urlSource.Path, destFile);
                    DbDebugHelper.OnSftpUpdate("caching " + urlSource.Path);
                    _db.Set(destFile, urlSource.Path, entry);
                }
            }
            else
            {
                if (_entries.ContainsKey(urlDest.Path))
                {
                    var entry = _entries[urlDest.Path];

                    if (_db.Exists(urlDest.Path, entry))
                    {
                        byte[] dataDest   = _db.Get(urlDest.Path);
                        byte[] dataSource = File.ReadAllBytes(sourceFile);

                        Crc32Hash hash = new Crc32Hash();

                        if (dataDest.Length == dataSource.Length && hash.ComputeHash(dataDest) == hash.ComputeHash(dataSource))
                        {
                            // do not upload the same file
                        }
                        else
                        {
                            DbDebugHelper.OnSftpUpdate("uploading " + urlDest.Path);
                            _sftp.Put(sourceFile, urlDest.Path);
                            DbDebugHelper.OnSftpUpdate("updating cached version for " + urlDest.Path);
                            var newEntry = _sftp.GetFileListAdv(urlDest.Path)[0];
                            _db.Set(sourceFile, urlDest.Path, newEntry);
                            _entries[urlDest.Path] = newEntry;
                        }
                    }
                    else
                    {
                        DbDebugHelper.OnSftpUpdate("uploading " + urlDest.Path);
                        _sftp.Put(sourceFile, urlDest.Path);
                        DbDebugHelper.OnSftpUpdate("updating cached version for " + urlDest.Path);
                        var newEntry = _sftp.GetFileListAdv(urlDest.Path)[0];
                        _db.Set(sourceFile, urlDest.Path, newEntry);
                        _entries[urlDest.Path] = newEntry;
                    }
                }
                else
                {
                    DbDebugHelper.OnSftpUpdate("uploading new file " + urlDest.Path);
                    _sftp.Put(sourceFile, urlDest.Path);
                }
            }
        }
Example #6
0
 public SftpFileManager(string path)
     : base(path)
 {
     _info = new FtpUrlInfo(path);
     _sftp = new Sftp(_info.Host, ProjectConfiguration.FtpUsername, ProjectConfiguration.FtpPassword);
 }