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.
Related
I am currently writing a c# application that includes file synchronization so that files can be provided for other clients and used offline. I thought of using the Microsoft File Sync Framework (.NET) to take care about the synchronization itself: https://msdn.microsoft.com/en-us/library/mt763483
We do have a MS server 2016 that could be used as a file server by creating a public share, but I am not sure if this is the correct way to do it (referring to security). I was also thinking about using (s)FTP or WebDAV to provide the files in order to have a secure connection. Is there a best practice how to do file synchronization in c# applications over the internet using a microsoft server without implementing your own server application?
Thanks in advance.
Using WebDAV finally worked great for me.
I write small apps to help automate daily work of some colleagues and want to put on a shared folder on my machine so that others from local network can execute when my computer is on. I don't have the luxury of my own server so this is the best I can do.
One of which is a Winform app that connects to an Oracle database via an Oracle client and Oracle Data Access installed on MY machine to retrieve information. I would hope that people can execute the app (.exe file) when my machine is on, without installing anything on their machine. The app will write to an output file (.html) on the same folder and open it on THEIR browser.
My question is : What should I do to make it possible ? How can people run this .exe file using Oracle Client, Oracle DataAccess and .Net framework already installed on MY machine as if I am running it locally.
I mark all C# Assemblies (automatically added by Visual Studio) as Copy Local to True (Microsoft.CSharp.dll, System.Data.dll, System.dll, System.Data.DataSetExtensions.dll, System.Deployment.dll, System.Drawing.dll, System.Net.Http.dll, System.Windows.Forms.dll, System.Xml.dll, System.Xml.Linq.dll). Would people still need .Net framework installed ? My app is quite simple with only one external dll Oracle.DataAccess.dll. How about Oracle client and Oracle Data Access.
Many thanks.
Best solution for your situation is create a webservice and make the clients that'll consume your webservice instead of them making direct calls to your database. It removes system dependencies and easier maintenance.
Your colleagues can go to your computer via remote desktop if it is feasible. In the probable case that this is not feasible, you need to decide what the colleagues will see. If they only need to see the generated html and they only need to trigger the execution of your exe, then you will need to have a program which listens to a port and make sure that the given port is requested correctly by your colleagues via a small client app.
But honestly, the use-case you describe sounds like a website used by your colleagues. You can create a website in .NET, the exe you have would be the controller or code-behind depending on the approach you use and the HTML would be the response. Then the colleagues will just request your page with the port you are listening at.
If my .NET client uses System.IO.File.Copy to copy a file from \server1\share1\file1.txt to \sever1\share2\file2.txt, the file's data get read down to the client and then written back up to the server.
Is there an easy way to speed up things a bit by putting a process on the network-machine that realy does the copying?
I dont look for advice on programming such a service. I would rather find the tool or windows-functionality that already does this.
This sounds like a job for telnet or ssh, but these can be a pain to set up. I recommend you look at PsExec from microsoft which allows you to execute programs on a remote machine. You could simply use the copy program found in system32 through PsExec.
There is no need to create your own program to do this, just use the command line tools found on the target machine.
Almost certainly. I can think of a couple basic ways to do it:
Create a simple console applicaton that takes the source and destination paths/filenames, and performs a File.Copy(). Place it on the remote machine in a known location. Then invoke the process on the remote machine using PsExec. Your client app must be running in full trust in order to invoke a process programmatically, and the user running the app must have permission to run programs on the remote server.
Create a simple web method that again takes the source and destination and performs the copy. This requires setting up IIS on the network server with the requisite permissions to perform file access outside of the IIS "sandbox". However, it requires fewer client code permissions.
FYI CopyFileEx already does this if your client and server are Vista and later. So, not point in duplicating any of that effort in that case.
-scott
I'm working with with asp.net and writing a few classes (controls for the CMS) to use on my website. At the moment i'm using a text editor (UE) which has sftp support and syntax highlighting to edit the files and save via sftp. Then i just test it out on the test site. It's working well.. but since i'm very new to c# i'm always looking up methods,argunments etc.
Not unpossible but a pain.
So this is where Visual Studio comes into it. I'd like to use VS so i get auto-complete and the hooks to MSDN. However i'm not interested in setting up a local environment to work in as i already have a test environment at my webhost, and frankly it's the differences between my set up and the host (ie: the CMS, unicode issues, dates...) that are the trickier bits.
Is there a way to use Visual Studio with a remote site accessible only by sftp?
One way to do this would be to mount the SFTP server as a windows drive.
If the SFTP server is on your local network then you can mount it as a windows share. If it is outside your network on in your DMZ, then you can find software that lets you mount the SFTP server as a drive.
Software that allows you to do this include ExpanDrive. This would allow you to use Visual Studio as normal whilst behind the scenes the files are uploaded to and downloaded from the SFTP server as required.
Well, it's an answer:
My first thought is just setup FileZilla to send the directory of your "published" development website. This would be the easiest setup, and frankly the fastest way to get content to your server.
If you are specifically looking for an in-application way to do this:
Visual Studio is setup to accept embedded applications. For example: VIM (Vi Embedded). You can simply load an sFTP savvy embedded app.
One example:
From VIM Docs:
Network-oriented file transfer under Vim is implemented by a VimL-based script
() using plugin techniques. It currently supports both reading
and writing across networks using rcp, scp, ftp or ftp+<.netrc>, scp, fetch,
dav/cadaver, rsync, or sftp.
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.