SftpService | Working with SFTP in .NET Core | Command Line Interface library
kandi X-RAY | SftpService Summary
kandi X-RAY | SftpService Summary
Working with SFTP in .NET Core
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of SftpService
SftpService Key Features
SftpService Examples and Code Snippets
Community Discussions
Trending Discussions on SftpService
QUESTION
Whenever I try to upload a file to the SFTP server with the .csv
file extension the only thing within that file is System.IO.MemoryStream
. If it's a .txt
extension it will have all the values in the file. I can manually convert the .txt
to .csv
and it will be fine. Is it possible to upload it directly to the SFTP server as a CSV file?
The SFTP Service is using the SSH.NET library by Renci.
Using statement:
...ANSWER
Answered 2020-Apr-03 at 06:10It looks like the csvFileWriter.Write
already returns MemoryStream
. And its ToString
returns "System.IO.MemoryStream"
string. That's the root source of your problem.
Aditionally, as you already have the MemoryStream
, its an overkill to copy it to yet another MemoryStream
, upload it directly. You are copying the data over and over again, it's just a waste of memory.
Like this:
QUESTION
I can't figure out why my dependency injection is not working as expected, when my controller is hit the constructor of MyFirstService
is being hit again and therefore I am hitting a different cancellation token to the one I wish to be when calling the StopFeeds()
method.
I have tried to add the controller in as a singleton and use the controller's StartFeed()
method to instantiate the class but no matter what I do with DI (general ctor DI, explicit property assignment, [FromServices]
and even directly passing in the service collection) when I hit stop feeds it will create another instance of MyFirstService
... Any ideas?
Interface:
...ANSWER
Answered 2020-Jan-07 at 13:52This is not intended as an answer (hence community wiki). However, I felt this was important, nonetheless, and wouldn't be possible to cover clearly via a comment.
You should not inject IConfiguration
into a service like this. That creates a tight coupling between your configuration and the service, both the method of obtaining the configuration (Microsoft.Extensions.Configuration
) and magic strings like MySection
. If the format of the config should change, your service will break, because it's depending on things (both the knowledge that there's a MySection
section in the config, and how that config is retrieved) that it shouldn't actually know anything about.
Instead, you should always just inject the information you actually require, i.e. the values of Host
, Username
, Password
, etc. When there's a lot of tokens like this, you might instead consider creating an options class to encapsulate them, and then inject that instead. For example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install SftpService
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page