I have a Java application that downloads a file from a remote server. I would like to know where the application actually downloads a file. I captured a TCP/IP packet and found the below information.
protocol: TCP
remote address: xxx.xxx.xxx.xx
local port: xxxx
remote port: xxxxx
I know exact file URL now. However, when I try to access the file using web browser I see:
Internet Explorer cannot display the webpage
Since the application is compiled by java, there must be a way to do it in C#.
Just because the Java application is able to download the file doesn't mean they're doing it via HTTP. The fact that IE fails to display anything useful suggests it's not HTTP, although that's no guarantee.
You should look at how the Java application downloads the file, and determine the protocol - that should tell you how to do the same thing from C#.
Of course, this is assuming you have the code for the Java application. If you don't, but you think the authors would be happy for you to download the file with your own code in C#, I suggest you email them to ask them the protocol. If they don't want you accessing the file other than with their application, I'd personally respect their wishes.
Related
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)
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 to make a windows application to upload files (jpg) that are on my computer to a web host. I have tried various codes I found on the web but none of them worked.
Does anyone have a working code to do this? Maybe in VB.NET or C#.
I appreciate the help.
Your question is not revealing more details about your requirement, but still I'm providing couple of ideas on how do that based different scenarios.
First point: you need to be clear about your server side for receiving these files. Whether you want to activate ftp on server and provide ftp credentials to client to upload files to a particular folder. If not ftp then you should have your server listen to post requests from the client to upload files.
FTP: Here is the article to upload files from windows application to a FTP server.
Post: Here is the link for post way.
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.