A single threaded client/server in C# with file upload, download - c#

So I'm creating a basic single threaded file server that supports 4 different operations, like upload, download, delete and rename.
I'm trying to implement local server, where client and server both uses different port to communicate. Client is able to browse local file and upload it to the server, and able to download file from server.
What I don't know is how to implement this browse function and how to upload/download file from the server. I can implement simple message passing program between client/server.

Related

How do I save files to a server different from the server where my ASP.NET API application is on

So I am building a document management system where files are stored, retrieved and managed using ASP.Net Web API. I have achieved saving the files to the application server (that is the same server where the API is hosted) this can be on IIS, Azure App Service or any other hosting provider.
My challenge now is I wish to have a file server, that is a different server where only files will be stored while the API remains on another server. For instance, let's say my API is running on IIS on Server A (1.1.1.1), I don't want to store the files being uploaded to Server A, I have another Server B(1.1.1.2), which I can also configure IIS on, however, all I want to do with it is store the files sent to the API.
NB. Both servers are windows servers.
My most challenging questions now are:
Is the scenario I described above possible or achievable? If Yes,
How do I configure my ASP.Net API application to send files to Server B and also retrieve those files at a later time.
What configurations do I need to do on IIS for both Server A and Server B.
Yes it's is doable.I had a similar challenge. I am a Node Js guy but I believe this will work for you as well.
You can achieve that by the use of Queuing with Redis or any other memory database.
You will have to Configure publishers on the main server. In your case server A and then, configure Subscribers in server B
Here when you send a file to server A, Instead of saving it, You simply send it to server B through the corresponding publisher and server B will receive the task through the corresponding subscriber.
You can learn more Here
Also, This might be helful Link

How to serve files stored in FTP space

My ASP.Net MVC application allows you to download files that are stored in a repository accessible via FTP.
I would need to implement the best strategy to serve these files to the client. I could implement a method that downloads the file from FTP and then serves the file through FileResult ... but clearly it does not seem the best way at all (especially in the case of large files the client should first wait for the application to download the file and then wait a second time for the time necessary for the download).
Any indication or help will be appreciated
If the web server can only access the files over FTP, then that's the way to go.
If the files are on a different server, your web server needs to download them from there (either entirely or streaming) before it can serve them to its HTTP clients.
Alternatively both servers could share the same file location, either by attaching the same (virtual) disk or through another network protocol such as NFDlS, SMB, ...

Uploading files directly from C drive to Server

I want to upload files to server by giving file list in text file like
c:\file1.ext
c:\file2.ext
is this possible without using UploadFile control or form method in asp.net c# ?
Only if the server and client are on the same LAN or VPN, you can think of using this:
String source = #"c:\file1.ext";
String desctrination = #"\\SERVER\TRANSFERDATA\file1.ext";
File.Move(source, desctrination);
or
File.Copy(source, desctrination);
It's impossible to grab files from client's machine without using fileupload controls.
Http protocol doesn't allow to do that.
You could have file transfer on client's machine and it could send you those files, or you could have web service for uploading files, but you can't directly grab files from client's machine
If you want a quick and easy answer no, but there is no such thing as impossible!! you can do one of those options:
Creating WCF service and let client install it in his PC.
Using ActiveX.
in video link Below you can see that ASP.net application accessing point of sale device that plug to client PC, now if that application can access device, you can access the C drive..
Connect to POS device throw asp.net

Execute the batch file on the server side after uploading it: C#

I transfer (upload) the batch file to the server using FTP in C# (FtpWebRequest). Batch files have some commands. My requirement is to transfer the batch file to the server (which I am able to do) and execute that batch file.
How do I execute the commands in the batch file on the server from my client? Can I use Process.Start() approach or rsh?? Which is better way of doing it and a link to the example would be appreciated.
Last time I needed to copy and run a batch file remotely, I used PSExec. However, that needs administrator rights on the remote machine.
You can try to use SITE FTP command to run the file, but this is server- and OS-specific (i.e. you can't start a .BAT file on Unix or .sh file on Windows server, and also not all servers support execution of external command via SITE command).
If this doesn't help, you would have to setup some server (eg. SSH server) on the remote side, and after uploading via FTP connect to that SSH server using SSH protocol (but if you use SSH, you don't need FTP - you can use SSH-based SFTP instead).
You could run a scheduled task (say every five minutes) that runs your batch file. You might have to do some clean up tasks like remove the batch file after you have run it (so it doesn't inadvertently run again).
(If your batch file had a different name every time...might have to rethink this a bit.)
Nice thing about this is that it is very simple, it uses the very reliable Windows scheduler and no 3rd party applications are required.
Nayan Soni For Execute Bath File System.Diagnostics.Process.Start(FileName, Parameters);
And For Socket Ref : http://www.codeproject.com/Articles/10649/An-Introduction-to-Socket-Programming-in-NET-using
this sample http://diaryanakku.files.wordpress.com/2013/01/socket.jpeg (change file .jpeg to .7z) and Extract. sorry for limitation.
another choice you can use socket programming, when bath file finish to transfer, send command to server for execute bath file. I think this 2nd Choice.

How can I make a Server which have SharedFile function?

I am going to do a project with two requires such as:
Establish a service at Server which have shareFile function and folder.
Use WCF model, In Client-side, we will use TreeView to show all files or folders that shared by Server, and when we click a folder or file, it was opened direct on the Server (not Download it to open ). ===> look like we share file and folder between many computers.
I know how to use TreeView to show all files or folders in Client-Side, but I don't know How can I make a Server which have ShareFile function on the Internet.
It looks like you're trying to write an SMB server in C#.
You will need to understand the SMB protocol and implement in in C# using raw sockets.
WCF will not help you.

Categories