I have previously implemented an application that connects to a FTP server and downloads/uploads files. This time i need to create the same kind of application but i have a problem. I don't know how to use the PPK(private key) file to connect to the server.
Application specs:
Connect to Server using SFTP and PPK(no idea how to do this.).
Download files from the server and write them locally (this part i know how to do).
If u need more information u can just write them in the comments.
thanks in advanced.
Related
I am using VS 2012 and I would like to securely transfer files with a server after setting up an SFTP connection. I have heard setting this up in Windows is a big task compared to Linux. Can anyone tell me the exact procedure to follow.
Developments till now
As far as I know there are no .NET assemblies which let you do SFTP straight away. But we can use FtpWebRequest using the System.Net assembly.
But I wish to use SFTP. I found an application called freesshd which helps in implementing SSH server. I have also heard about
SFTP Blackbox and Rebex (both of which are paid versions).
Expected answer pattern
Step wise walkthrough from how to setup SFTP in a server to how to successfully connect with that server from a local machine.
Suggestions for tools, assemblies or 3rd party libraries which should be used to do this task preferably with link.
Detailed walkthrough on client side and server side modification to achieve this task.
I appreciate any kind of help on this one. Thanks in advance.
NOTE: This is for a Windows Form application and not a web application.
It's actually pretty easy, there's not much to it. You can download the Renci SFTP compiled client from https://sshnet.codeplex.com/releases/view/120565 (both .NET 35 and 40).
On the server side, you already mentioned freeFTPd, which will work fine for testing. Wouldn't recommend it for production level. Add a user and password and home directory. Then start the server listening.
On the client side, using Renci, create a new StfpClient object connecting to 127.0.0.1 on port 22 using the username and password. For the client to authenticate the server, you can listen to the client.HostKeyReceived event.
The only pitfall I've found with Renci is when trying to manually open the stream using FileMode.Create. I expected it to overwrite the existing file, but it always appends to the file when uploading. Internally it maintains its own flags, but those flags don't line up with the expected behavior of the System.IO.FileMode enum. I was able to truncate the file by uploading an empty MemoryStream and then use the Open method for Renci. The Delete and DeleteFile methods didn't seem to work either, which could be a bug in freeFTPd, haven't tested using another SFTP server.
I would like to access/read a text file that resides on a remote windows server. The local computer and the remote server are not connected to each other i.e. they are not part of a network or under a domain. Is there any possible way, using C#, to access and read the contents of that text file?
P.S.: The remote server requires a username and a password to log on to it. I'm the server admin and thereby I am aware of those credentials.
Thank you in advance!
C# is a programming language. You could implement a Windows service application that will listen to connections and then dump the contents of anything you'd like. There is nothing natively implemented in C#, however, that will allow you to immediately do what you're asking.
As long as both machines have internet access, and the network they're on will allow outside connections past the firewall, there are some examples online that will get you heading in the right direction. Example.
Be wary, however, that if you implement your own server application that will host files over the internet, you will have to also implement your own credential checking mechanism. Even if your server requires authentication, that will have no affect on your server application.
Hello and thanks for the replies! I have exposed the contents of the remote text file using a RESTful service. The local computer can now use the data stored in that text file by just navigating to the url where the service output is returned.
I need some suggestion about how to save .pdf file from server to client side. I'm using C# console application to generate pdf file and save in server local c and I manage to do it by using .ExportToDisk(ExportFormatType.PortableDocFormat, report). Now I need to save the file to client side rather than save in server local c because my user aren't allowed to access the server. Appreciate if someone can help me about this. Thanks
Your best option would be to export to a UNC path which the users can access. Don't forget your console application will have to run as a user with write access to the UNC path.
Full edit:
The scenario is that after uploading the file to the server via a secured web service, I'd like to save/create a copy of that file to another server in a LAN or another network.
I'd like to know what possible ways I could use to programmatically copy/create the backup of the file uploaded to the backup server (saving the file to the database would be the last option probably).
Here are a few details:
Files are of different types and sizes mostly text, documents and images that would be around a few KB to a couple of MB's.
Database is SQL Server 2008 R2 and the only way to connect to it is via calls to a secured WCF service.
Servers can be in the same LAN or on separate networks (depends on the client requesting).
The 2nd server is a redundant server and is using the 1st one as it's backup and vice versa.
Took me a while to find this post. Just map the drive to the backup server's shared folder and implement WindowsImpersonationContext.
How to Impersonate a user in managed code?
haven't seen security problems on this and doesn't need to mess with the HTTP/certificates.
We have a C# windows application that needs to be able to connect to a server on a network, download and save a file to a specified location.
We can not use a web service as we can not assume that our clients will have IIS on their server.
The way that I am considering doing it is to FTP onto the server and download the file. I can write the code to connect to the server and located the file but I have 2 questions.
Is there a way of using the windows credentials to FTP on to the remote server? (I understand that I cannot directly get the user's password).
Is there a better way of getting the file from a server other than ftp-ing on to it?
Thanks for the advice.
I'm assuming that a network share isn't an option (perhaps an external site etc).
Note that IIS isn't the only way of hosting a web-service. With WCF, you can use a console exe or a windows service to host the WCF service, which would allow you to run WCF on the server without any mention of IIS. See here. Then all you need is line-of-sight to the server, and some code that returns the file (or chunks of it, or a stream of it).
Depending on the size of the file (e.g. if it is less than 4MB) - you might consider leveraging a public MSMQ mechanism.