Spike exploration: sftp, zip, config and Windows Service
I did a spike exploration to find out what is involved in creating a Windows Service with event logging. I also wanted to find out what is involved in working with sftp, zip and configuration with C#. The code is available on github: https://github.com/k0emt/sftp-windows-service-spike
In order to test the sftp code I set up a Linux VM in the Azure cloud environment and created a user account on it.
I use the ssh component from http://sshnet.codeplex.com/ for sftp. It is very straight forward to use this component. The key for sftp is to use the SftpClient class. Upload a file with the UploadFile method. The sample code is in the ConsoleSftp projects Program.cs: https://github.com/k0emt/sftp-windows-service-spike/blob/clean/ConsoleSftp/Program.cs
Use System.IO.Compression for creating/expanding zip files.
To use the ZipFile class, you must reference the System.IO.Compression.FileSystem assembly in your project.
I use ZipFile.CreateFromDirectory in the code above to zip an entire directory before sending it over sftp.
ConfigurationManager is the class that is used for working with application settings.
I used it in the service code to pull in a setting called user: https://github.com/k0emt/sftp-windows-service-spike/blob/clean/TransferService/TransferService.cs
In order for this to come together, you must create an app.config file in your project and change the property setting in Visual Studio to tell it to deploy when the project is built. https://github.com/k0emt/sftp-windows-service-spike/blob/clean/TransferService/App.config
Windows service with event logging
Create a Windows Service by choosing the Windows Service project template.
The Windows Service code must be installed and uninstalled. It is possible to create an installer/uninstaller. I opted to use the command line for this spike.
I went here to learn about Service Methods