File synchronization between c# application (.NET) and microsoft server - c#

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.

Related

Visual FoxPro data in .NET

We are in the process of migrating an old VFP application into a .NET WPF application with SQL server.
During the process we still need to read/write to the DBF files to keep our business working properly.
To do this, we use the standard OLEDB adapter that is available. However, our sysadmin is asking if we have an alternative way to access the DBF files.
Having each user connect to the files is not the best option from a network/security perspective. Specially when connecting from home through a VPN.
I've already tried to move the connection to a single server by exposing the data through an API. But that was slowing down the application too much. In some situations we synchronise the data through background jobs (Hangfire implementation). But this can be time consuming to implement.
Has anybody used any other techniques to do something similar while migrating a VFP application?
OLEDB is still the best option. Within the application, you could impersonate a specific user that has access to files.
Also Sybase Advantage Server can connect and work with VFP data files. Local mode is (was) for free and server mode paid. You might try checking that too.
Locate data on single PC as server. Access via RDP - kludges available to support multiple connections. Increase security if needed by connecting over VPN - then RDP.

How can I implement a simple server to receive files sent via WebClient in C#?

There is a program which sends image files in binary by using WebClient.UploadFile(someUri, "STOR", filename). I can't change that program, but I need to build a program to receive the file. I don't want to implement a full FTP server, so what should I be looking at to create the bare minimum logic in C# to receive the file? A bonus would be a solution that uses features present in .NET 3.5 or 4
I don't really know where to start, so any tip is appreciated. Thanks.
It sounds like you'll need to provide not an FTP server, but an HTTP server (aka a web server). From a little quick Googling, it looks like there's a library for embedding a simple web server into a .net application named Nancy that a lot of people seem to have good results with: Embedded C# web server?
Of course, this would be the quick and dirty way. Probably a better long-term approach would be to create a normal ASP.Net website to receive the images, hosted on a normal IIS web server. But if you have no experience in web development, that might be biting off a lot.
Thank you for the suggestions, but through more digging around I found out how to implement what I need. This is a very simple ftp server done in python using sockets. I was able to easily replicate this in C# using sockets again and I have adapted it to be able to authenticate a user of my choosing and write the received files to the disk.

What are the requirements to setup an SFTP connection in Windows C#?

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.

File management best practices

Hi I am currently working on a WPF application which needs extensive file management (users should be able to upload files to a central server and download files from that server)
currently i have created a fairly simple wcf based server to handle these requests.
i was wondering if there are any better ways to do this like third party apps or features in windows server, sql server, wpf that i am not aware of ...
Sql Server 2012 Has a new Feature on Top of FileStream, it's called FiledTables.
There you also have a fileshare which is syncronized with your filetable
Tutorial
For storing: Read about FILESTREAM capabilities in SQL Server 2008 for storing and accessing large files in SQL just thru file system.
For uploading/downloading: have no clue for you right now..
Have you looked at using WebDAV with IIS?

N-Tier with C#?

I am looking at writing a WinForms app and getting stumped over what seems to be simple issue.
There is a server and database (SQL Server) Open ports are HTTP, HTTPS
There is a WinForms client. It needs to connect a TCP/IP stream (possibly HTTP, SOAP, REST) to the server.
Sometimes the WinForms client goes off-line and then the WinForms client stores its data in a database.
When the WinForms client goes on-line to server, it synchronizes data to the server, gets all the latest data from the server and updates local database.
How do I do that?
Newbie question
As you've conceded, this question shows you might not know where to begin looking for how to architect this kind of application.
I'd start here: http://msdn.microsoft.com/en-us/library/ms973279.aspx
The offline architecture you've described is a little tougher for a newbie than not supporting this, consider making the application only work online first, then add offline functionality.
Also, if you have a web server you will almost always use HTTP, SOAP and REST are strategies that sit on top of HTTP. I cannot recommend that a new developer look at any server communication using direct TCP/IP.
Edit: Answer to related question - there are tons of ORMs and service builders, not a lot of them have built in support for offline workflow but ODX does, but it might be a bit out of date. NHibernate and any of the projects in the Castle Project are very popular components for what you're looking to do also.
No idea how actively this is still being supported by Microsoft, but you might check out the Smart Client Software Factory, it seems to support offline mode and smart reconnecting like you need.
http://msdn.microsoft.com/en-us/library/ff709809.aspx
You could approach this with a 'Service' mindset - Write a WebService (preferably a WCF service) - that forms the synchronization tier between your Winforms app. and remote database.
So, you would have your
1. Local WinformsApp. with a local database (as functional/lightweight as you want it to be)
2. WebService
3. Remote app./DB
Here are some links to tutorials/resources:
http://www.codeproject.com/KB/architecture/three_tier_architecture.aspx
http://services.community.microsoft.com/feeds/feed/query/tag/n-tier/eq/tag/visual%20basic/eq/and/locale/en-us/eq/and
http://msdn.microsoft.com/en-us/library/bb384570.aspx
http://msdn.microsoft.com/en-us/library/bb384398.aspx
IMHO this isn't usually as simple as it may sound
If you were able to go DB to DB, then SQL replication could be the simplest mechanism for synchronisation.
However, since it sounds like you are using a SOA approach, you might need to look at frameworks which have offline support built in, such as the Ent Lib Composite Application Block and Smart Client Software Factory
You might also look at using Queues (e.g. MSMQ) to accomodate network connectivity problems.
Microsoft Sync Framework (http://code.msdn.microsoft.com/sync) + WCF solution here:
http://code.msdn.microsoft.com/sync/Release/ProjectReleases.aspx?ReleaseId=3762
Database synchronisation is not an easy task to get started with, by any means. Good luck.
Generally, you need a local database, or at least a local cache.

Categories

Resources