In c# I've assigned to write code for download and upload docx file from local server machine to the same local client machine. Let me explain clearly,
For example: If i need to send docx file (C:\sample.docx ) to client machine into directory(D:\sample) using web server(Here using apache tomcat) .. Here using httpwebrequest & httpwebresponse classes..
Is there any possible to find out the solution?
Trying simple client - server application, It’s like a file sharing (Server assign word file to client and then client download that assigned file), I'm done with sockets-TCP/IP that’s works really fine. But trying to work out using http...
You cound not send something for Server to Client. Client have to request, Server have to respond.
This is a rather simple task. You can just place your file into web site folder (~/sites/mysite/simple.docx), if appache is configured and you requested http://mysite/simple.docx, file would be returned as response.
WebClient class DownloadFile method is very suitable for that.
Related
I would like to know if somehow any client using any browser can see my server side code? if it is so how could I prevent this and actually what is the client able to see when he is visiting my web site?
(asp.net)
I've never used asp.net before, but i assume it's the same like PHP or Perl. The client only sees what the server is sending to him (like any other network application).
The normal order of execution of things should be ->A client sends a request to a specific resource. Your server interprets this request and opens the required files for processing. Then a parser goes through your source files and executes your code.
The only way of source code being send to the client is a typo where you miss the " at the end of your strings.
In a server / client environment, I need to send a plain text file over the HTTP protocol.
Typical scenario:
A client joins the server, and the server sends a string telling the client a url to download a text file. The URL would be:
"IP:PORT/folder/folder/file.txt" (where 'IP' and 'PORT' are actual
IP's and Ports IE: 127.0.0.1:1234)
I need the server to allow a connection to the files location, and the files location alone.
The client is closed source, and so I have no control over its code. It should act like a HTTP server, but only for that file, or at least the subfolder. You should be able to type in the URL into a browsers address and read the contents of the file.
What's the best way of doing this?
The easiest way would be to use the HttpListener class.
The documentation contains an example which shows you how to set up the listener and receive a request, but it does not directly cover how to check what file was requested and how to feed that file back to the client. However, both are easy to do and would not take a lot of code.
You can try to use an existing webserver like Apache to serve those files.
Also if this is some kind of learning exercise. You can implement your own simple HTTP server in C#
I am working in a multiple server environment and so have created a Management Program to start, stop and open pages on my Tomcat servers.
I want some way to determine from C# whether the server is up at any particular point. I have tried connecting to ports but haven't had any luck. Does anyone know how to do this? Poll a port on an IP address to determine if Tomcat has been bound to it?
What you can do is create a windows service or forms app which uses httpRequests to request a specific page on your tomcat server. This page can for example contain the text "server online"
In the httpResponse class it's possible to read the contents of the returned html code by the server.
If this html contains an error message, your server is probably down or misconfigured,
if it contains the right text, your server is up and running.
You can also try to create a program to check the windows service status for the tomcat service.
Note this will only tell you the service is running, not that it actually works the way it is supposed to.
You have to use JMX in connection with a web service maybe.
I'm working on a project that has a C# app (running 24/7 as a server) on the client's machine). This app needs to send a file as a byte stream via POST to a server I am currently hosting on my home desktop.
Can this file be received by a C# app running on my server, or does it have to be as ASP app/page?
Also, I know how to send a bytestream via POST, but how will I set my server side app to listen for this incoming data?
I have never done something like this, so I'm looking for some pointers to get me started.
Thanks
Depending on what you need to do with the file, and when it's uploaded, there is nothing wrong with using a tiny asp.net app to do this.
If the only way you can get the file to the server is via http POST, why write your own service/daemon to run a listener? Unless you have some reason not to run it in IIS, I would do it there. There is the full stack available that way for authentication and so on if you should happen to need it. Besides, if you have to upload files via http post, I would bet you will end up wanting other methods available via HTTP as well..
You're looking for this guy:
http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx
Using that, you'll create basically a mini HTTP server, listening on some port you specify. You'll then be able to post data to it, and process it accordingly (similar to if the processing code was in an ASPX code-behind).
Assuming your open to sending directly via TCP you can look at this example if you dont wanna go the HTTP way. I personaly like the NetworkStream Class, for sending data over the network painfree.
I am trying to create a ftp server in c#.
This server should listen to any ftp requests, and if a file is sent from a remote location, then the server should write it to a specific folder.
I am using VS2008. Do I need a tcp listener? FtpWebRequest? FtpWebResponse?
Don't know if writing your own FTP server is the way to go here.
Wouldn't it be easier to install a pre-rolled FTP server, and have a job that polls your FTP upload directory? This job will identify incoming files and then places them where you need based on a set of predefined rules.
Can't you extend IIS ftp service?
For example: http://learn.iis.net/page.aspx/673/how-to-use-managed-code-c-to-create-an-ftp-authentication-provider-with-dynamic-ip-restrictions/
Or as you asked: http://learn.iis.net/page.aspx/579/advanced-logging-for-iis-70---custom-logging/
I believe a TcpListener would be easiest to work with
There's an old article on it here that should still be usefull: codeguru