Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- static void Main(string[] args)
- {
- const string host = "xxxx";
- const string username = "xxxx";
- const string password = "xxxx";
- const string workingdirectory = "xxxx";
- const string RemoteFileName = "xxxx";
- const int port = 22;
- Console.WriteLine("Creating Client and Connecting");
- Stream stream;
- using (var client = new SftpClient(host, port, username, password))
- {
- client.Connect();
- Console.WriteLine("Connected to host");
- client.ChangeDirectory(workingdirectory);
- Console.WriteLine("Changed directory to {0}", workingdirectory);
- var listDirectory = client.ListDirectory(workingdirectory);
- Console.WriteLine("Listing directory:");
- foreach (var fi in listDirectory)
- {
- Console.WriteLine(" - " + fi.Name);
- }
- stream = new MemoryStream();
- client.DownloadFile(RemoteFileName, stream);
- client.Disconnect();
- }
- if (stream != null)
- {
- if (!stream.CanSeek)
- {
- throw new Exception("Won't work :(");
- }
Add Comment
Please, Sign In to add comment