Example #1
0
        private void UploadFile(LocalFile localFile, SftpClient ftp, string path)
        {
            Console.WriteLine($"Uploading {localFile.RelativeName}");

            using (var stream = File.OpenRead(localFile.FileName))
            {
                var filePath = localFile.RelativeName.Replace(Path.DirectorySeparatorChar, DirectorySeparator);
                UploadStream(stream, ftp, path, filePath);
            }
        }
Example #2
0
        private void UploadFile(LocalFile localFile, SftpClient ftp, string path)
        {
            Console.WriteLine($"Uploading {localFile.RelativeName}");
            using (var stream = File.OpenRead(localFile.FileName))
            {
                var filePath = localFile.RelativeName.Replace(Path.DirectorySeparatorChar, DirectorySeparator);

                var fullPath = path + filePath;

                EnsureDirExists(ftp, fullPath);

                ftp.UploadFile(stream, fullPath, true);
            }
        }
Example #3
0
 private void AddHash(LocalFile localFile)
 {
     using (SHA1Managed sha1 = new SHA1Managed())
     {
         using (Stream stream = File.OpenRead(localFile.FileName))
         {
             FileHash fileHash = new FileHash();
             fileHash.Path   = localFile.RelativeName;
             fileHash.Lenght = stream.Length;
             var hash = sha1.ComputeHash(stream);
             var sb   = new StringBuilder(hash.Length * 2);
             fileHash.CreatedAt = File.GetLastWriteTimeUtc(localFile.FileName);
             foreach (byte b in hash)
             {
                 // can be "x2" if you want lowercase
                 sb.Append(b.ToString("X2"));
             }
             fileHash.Hash = sb.ToString();
             hashes.Add(fileHash);
         }
     }
 }