Beispiel #1
0
        public void DownloadToLocalFile(string filePath)
        {
            var connectionInfo = _connectionInfo.CreateConnectionInfo();

            using (var client = new SftpClient(connectionInfo))
            {
                client.Connect();
                using (FileStream fs = File.OpenWrite(filePath))
                    client.OpenRead(Path.Combine(_path, Name)).CopyTo(fs);
            }
        }
Beispiel #2
0
        private IEnumerable <SftpFilesValue> GetFiles(SftpConnectionInfo sftpConnectionInfo, string path)
        {
            var connectionInfo = sftpConnectionInfo.CreateConnectionInfo();

            using (var client = new SftpClient(connectionInfo))
            {
                client.Connect();
                var files = client.ListDirectory(path);
                foreach (var file in files)
                {
                    yield return(new SftpFilesValue(sftpConnectionInfo, path, file.Name));
                }
            }
        }
Beispiel #3
0
        private void WriteSftpFile(SftpConnectionInfo sftpConnectionInfo, string outputPath, Stream stream)
        {
            var connectionInfo = sftpConnectionInfo.CreateConnectionInfo();

            using (var client = new SftpClient(connectionInfo))
            {
                client.Connect();
                byte[] fileContents;
                stream.Position = 0;
                using (MemoryStream ms = new MemoryStream())
                {
                    stream.CopyTo(ms);
                    fileContents = ms.ToArray();
                }

                client.WriteAllBytes(outputPath, fileContents);
            }
        }