Reputation: 13
I've created a web app using Angular2 and wish to retrieve files (videos) from a remote server(which uses sftp). More specifically, I want to connect to a server through IP address and port 22 with user/password authentication. How can I establish this connection?
Thank you
Upvotes: 1
Views: 1490
Reputation: 56996
The usual approach for something like this would be to create your own backend server.
Make a request to your own backend server, sending any data that will be needed.
Then your server will do the sftp stuff and get the videos over sftp. Once it has retrieved the videos it will make them available over http.
Typically, it might go something like this:
browser ---> HTTP ---> your server ----> SFTP ----> remote server
then for the response:
remote server ---> video ---> your server
Now, I'm assuming that it will take some time for the videos to be fetched from the remote server.
There are 2 possible approaches for dealing with the delay.
(1) Preload all videos onto your server. This way, when a video is requested by the browser it should be instantly available.
This might not be possible if there are too many videos!
(2) After the browser makes a video request, return an HTTP 202 Accepted
response. This response says, I'm doing what you asked for but it will take a while. Also, in the response, it provides a URL that you can check to see if the video is ready. You then poll this URL to see if the video is now available or not. Or you could use websockets and then your server can tell the client (the browser) when the video is available.
For the backend server, I would recommend a Node.js express server. And then use an npm package like sftp-promises to do the sftp work.
If you want to host your server in the cloud use https://cloud.scaleway.com/#/login because it's very cheap and easy to use :)
Upvotes: 1