Accessing Directory Structure off Remote Machine - c#

I am working on application, which is divided in Client and Server part. Basically Server reads the TASK Database table, and perform the requested task and update database once complete. On other hand Client create Task entry as user desire.
Now some task are to read files which will be presented on Server machine, however we need Client to locate those files. For this I need to show directory structure of Server machine to client. So they can navigate to Folder structure and select relevant folder and files as per requirement. Also, at one stage we need Client to able to download the Files from Remote server.
On Server end we currently have Windows Service as it is mainly a background work it needs to perform and on client end I am using WPF based GUI.
Now, I am not sure what method I should use to access folder structure and to allow download of file. I have two options as I think
I create a TCP/IP Connection between my Client machine and Server machine. Then Server machine will pass Directory Structure as JSON To client and I show it on Custom build Tree View.
I create a Web service on Client end, and then consume that web service at client.
I can definiately use either of method to download files if I Can access folder structure. Now I find some drawback on either method.
on TCP/IP connection I have to maintain the connection between client and server which is otherwise not required as both application work independently. Infact with it's current architecture we can use application from outside domain or LAN.
With #2 solution, I am not willing to use default web server, as I am not sure if server are used for other parts in organization. So, I want to club this webservice with my Windows Service in background, is it possible if so, how? This give me fix address to access the service as well. But if I build on general webservice then I fear how I do the Directory structure reading does IIS or Apache allow reading of complete file structure?
Which solution is better and of course easy to code :) and maintain.

Related

How to dump an xml file generated from server to a random client, but I have to damp that file in a specific folder of clients

I was thinking to dump an XML file generated from server to a random client requesting that. The problem is that I have to damp that file in a specific folder of clients (C:/Application/POSMachine/WaitingXML), for there is another application listening to that folder.
My approach:
A simple patch (to change chrome download address to the specific desired path)
Installing windows service/local-api for those clients who need this feature, and passing server-side generated XML to clients installed service/api, I am assuming I will get clients IP-address from the server and hit the service hosted in clients.
Request.GetOwinContext().Request.RemoteIpAddress
Any comments and better implementation is appreciated.
It would be a security risk to allow a website to download a file to an arbitrary location (that would mean a malicious website could just download a new svchost.exe to C:\Windows\System32 or what not)
Also your idea with running a service would not work in all cases, since your clients will most probably be behind a modem/router/NAT switch (or multiple). All these devices would have to be configured for port forwarding. So, you really need an 'client-outbound' connection (like a browser does).
I would implement a client program which can contact your server and download the file with a System.Net.WebRequest and save to the specific location. Another possibility might be to add a System.Windows.Forms.WebBrowser control and handle the FileDownload event. However, your question does not contain enough information to more specific (how does the client chose a file to download)

Execute application on shared folder using resource of shared machine

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.

Hosting Webpage over Local Area Network in C#?

I have a C# form application that has different functionality. Additionally I want to add another service to the existing project which is hosting the webpage "CameraCapture.html" page over Local Area Network as a web service in order to be viewed from another client on the Network.
For this purpose I have added one form "frm_cameraServer_monotor" and two Buttons in this form, btn_StartServer and btn_StopServer, which to start serving "CameraCapture.html" and to stop serving it. My IP Address on LAN is: 10.140.191.200 (static).
I don't want to use any web server like Apache and ISS to be installed and configured. Just I want a server service to existing project.
Any one can understand and help me in this topic, really very appreciated Thanks.
I want to start web-service but without web-server
If it is just a plain HTML without back-end but not a web-service, then you can create a shared folder and open it as a file from your network. HTML and front-end JS scripts will work well. However, the link will be like:
file:\\COMPUTER-001\Camera\CameraCapture.html
If it is ok for you, then you can easily do this without web-server.
You surely cannot make it work this way without any HTTP-server:
http://COMPUTER-001/CameraCapture.html
Is it worth it?
Install a simple web-server, you even won't need to configure it if a single HTML file is everything you need.
If you want to host an asp.net site on your application (winforms/service/wpf/whatever) you can use CassiniDev
Then simply publish your web project to your filesystem and use:
CassiniDev.Server server = new CassiniDev.Server({port number}, {publishedSitePath});
server.Start();

Upload file to a remote server, how should I?

I am scratching my head about this. My scenario are that I need to upload a file to the company server machine(to a folder on c:) from our hosting one(totally different server). I don't know how I should do this. Any of you got tips or code on how this is done.
Thanks Guys
I would set up an FTP server (like the one in IIS or a third-party server) on the Company Server. If security is an issue then you'll want to set up SFTP (secure FTP) rather than vanilla FTP since FTP is not a natively secure transfer protocol. Then create a service on the Hosting Server to pick up the file(s) as they come in and ship them to the company server using C#/.NET's FTP control. Honestly, it should be pretty straightforward.
Update: Reading your question, I am under the strong impression that you will NOT have a web site running on the company server. That is, you do not need a file upload control in your web app (or already know how to implement one given that the control is right in the web page toolbox). Your question, as I understand it, is how to get a file from the web server over to the company server.
Update 2: Added a note about security. Note that this is less of a concern if the servers are on the same subdomain and won't be routed outside of the company network and/or if the data is not sensitive. I didn't think of this at first because I am working a project like this now but our data is not, in any way, sensitive.
Darren Johnstone's File Upload control is as good a solution as you will find anywhere. It has the ability to handle large files without impacting the ASP.NET server memory, and can display file upload progress without requiring a Flash or Silverlight dependency.
http://darrenjohnstone.net/2008/07/15/aspnet-file-upload-module-version-2-beta-1/
There isnt enough info to tell your whole hosting scenario but I have a few suggestions that might get you started in the right direction:
Is your external server owned by another company or group and you cant modify it? If not you might consider hosting the process on the same machine, either in process or as a separate service on the machine. If it cannot be modified, you might consider hosting the service on the destination machine, that way its in the same place as the files need to show up at.
Do the files need to stay in sync with the process? I.e. do they need to be uploaded, moved and verified as a single operation? If not then a separate process is probably the best way to go. The separate process will give you some flexibility, but remember it will be a separate process and a separate set of code to manage and work with
How big is the file(s) that are being uploaded? Do they vary by upload? are the plain files, binaries (zips, executables, etc)? If the files are small you have more options than if they are large. If they are small enough, you can even relay them in line.
Depending on the answers to the above some of these might work for you:
Use MSMQ. This will work for simple messages under about 3MB without too much hassle. Its ideal for messages that can be directly worked with (such as XML).
Use direct HTTP(s) relaying. On the host machine open a HTTP(s) connetion to the destination machine and transfer the file. Again this will work better for smaller files (i.e. only a few KB since it will be done in-line)
If you have access to the host machine, deploy a separate process on the machine which builds or collects the files and uses any of the listed methods to send them to the destination machine.
You can use SCP, FTP (of any form SFTP, etc) on either the host machine (if you have access) or the target machine to host the incoming files and use a batch process to move the files. This will have a lot of issues to address, such as file size, keeping submissions in sync, and timing. I would consider this as a last resort, depending on the situation.
Again depending on message size, you could also use a layer of abstraction such as a DB to act as the intermediate layer between the two machines. This will work as long as the two machines can see the DB (or other storage location) and both act on it. SQL Server Service Broker could be used for this purpose (and most other DB products offer similar products).
You can look at other products like WSO2 ESB or NServiceBus to facilitate messaging between the two apps and do it inline.
Hopefully that will give you some starting points to look into.

FTP Login using Windows Credentials

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.

Categories

Resources