![Ftp Ftp](http://www.c-sharpcorner.com/UploadFile/nkumar/FTPExplorerinCSVer2.012062005062334AM/Images/FTPExplorerVer2.gif)
This project is provided as an example of how to send files securely to an SFTP server using VB.NET and WinSCP.
This project is comprised of 3 main components that would need to replicated in a production software environment to work:
- SFTP Binary Library (WinSCP)
- SftpService.vb (SFTP Service/Wrapper Code)
- Application logic (sample ConsoleApp.vb in project)
Download all files from a FTP directory to a local folder, you will have to list all files in the remote directory and then download them one by one. Here is an example of the steps in action, using FtpWebRequest to download a file. Scenario: Let's suppose our vendors upload the files to one of the folder on daily basis on FTP Server. We need to create an SSIS Package that should be able to download all the files from that.
WinSCP
WinSCP .NET assembly / COM library offers the library to be used to facilitate connection over SFTP. It is leveraged by the wrapper service for ease of use.These files must be present in the project to work:
- WinSCP.exe
- WinSCPnet.dll
Installation instructions:
- Copy both files into project, make sure they are included in project
- Right click on References in Solutions Explorer -> click 'Add Reference'
- Click on 'Browse', locate .dll and add to project
- Right click on each file in solution explorer -> click 'Properties'
- Edit 'Copy to Output Directory' and set to 'Copy if newer'
These files must be in the final output in the same directory,you need to right click -> Properties, then set 'Copy to Output Directory' to one of the 'Copy ...' options.
SftpService.vb
This is the service class to copy and use as-is to provide the SFTP functionality with WinSCP
Included Example Key
The included example key has this public thumbprint to set on your server for testing:ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAniLOkUwxAVBayxWbODbPrTZ7pU/dkIQDj6VRZeAbUT+vChbZs3tuDO7oMTKl35ALWIim8/uHU2T62+tyNxZo7thuAYg4VfX9EBgOb7G8/HZQ6yamiX/xADP4y4Tci9I9DoLqf62XRu8dq72GXDzZUG668053K7iJRvMbTwnE6Hx1iIhoK44whHJYvA2ub8SAzJ2gJbU3xY/OCN8HFJL2KnjBVXo4pu0O3Tnbi7vmkqyod9Y01oXHztfnbm/j1kcDEUkqVAY1rfzQ0xGLo9SnFPcB2kiX/xHOM+4INUP6qrjAMhOVziSQRM1nBrsTZhtF82M122vBShonTcMObm+kpQ Example Key
There are 3 types of connections supported by the service:
Certificate Authentication (passphrase secured certificate)
Path to certificate must be complete and app must have access to path/file
Certificate that requires passphrase:
Certificate Authentication (unsecured certificate)
Path to certificate must be complete and app must have access to path/file
Certificate that does not have a passphrase:
Password Authentication
Supported actions
Uploading file to server:
Listing files in current directory:
Listing files in specific directory:
Deleting a file from the server:
ConsoleApp.vb
![Ftp Ftp](http://www.webhostinghub.com/help/images/stories/filezilla/overwrite-file.png)
This shows a sample of how to interact with the SftpService class, it represents samplecontrol code you would instead have in a production application