How to communicate FTP transfer with standalone PHP Server? - php

I have a Ubuntu Server on which I have my Apache and FTP server (I am using Proftpd server). I have a small PHP CMS and for database I am using MySQL server. This was my server side environment. Now on client side I have a C# ftp client which I use to download the file from FTP server. Also, this C# client communicates with my PHP CMS.
So in short there are two communications occurs at a time
1. C# client and FTP server for file transfer.
2. C# client and PHP CMS for some other work.
So, now what I want is real time progress (progress bar) of my ftp transfer on one of my CMS webpage.
Obviously one of thing I can do is that I can tell my C# client to upload it's download progress to PHP server using some web service or web socket and then I can show the progress of ftp transfer(basically progress of downloading of C# client).
But before doing this I just want to know that is it possible for my PHP server to check what FTP server is doing. Since, no communication occurs between them I don't know how to accomplish it? I have a MySQL server and I know that proftp can communicate with MySQL server and it has some predefined table in which I can store whatever is ftp server doing. But will it possible to use it to show a real time progress? Is their any other technique to do this or will I have to force my C# client to do it?

From what you say, you have no need to talk to the FTP server at all (except to download the file, of course). Your FTP client could upload the FTP transfer status to a Web socket (and why could it not display it directly?), there to be recovered by the CMS and shown in the page. By using sessions, you do not even need to actively save that information anywhere, provided the Web socket call properly initializes the session cookies.
In the FTP client download callback function just add a call to send the progress status to the server. There, a scriptlet will save it into, say, $_SESSION['download_status']. An AJAX call on the CMS page can then retrieve it and display it periodically.
Don't forget to also upload FTP session and exception status (transfer interrupted, etc.).

Related

Access files in remote computer with php

I need to create an application using php which is hosted in a server and need to communicate with a csv file located in clients local machine. Is there any way we could do this ? How can I connect to a remote csv file ? Is this possible ?
Server machine accessing a csv file directly from a client machine is not a good idea. It's a security threat indeed. Consider you are navigating some website and it's server is able to access your computer's file system!!!
There are various alternatives to achieve this, some of these might be:
Make the user upload csv files to server in order to make it
available to the server application
If the client and server are in the same network, then share the
folder on client machine to make it accessible from the server
etc... I would have preferred the first option as mentioned above.
As #AnthonyB mentioned in comment under your question, server can't directly call client, and that is true. Server is called "server" as it serves requests from the client.
To be able to give away files to remote requests, your client needs its own server application, like Apache HTTPD for example.
In case if you need continuously request client's server to collect files with your PHP server, what you are looking for called "worker". One of AWS tools called Elastic Beanstalk offers possibility to choose a server or a worker application during start up wizard for PHP. It is pretty straight forward and easy to use.
Please note, that your client must have dedicated IP address or use Dynamic DNS approach by pushing its IP to a DB (or directly to a server) where worker will take it from.
If you don't need dedicated worker, you can configure CRON JOB to send requests to clients server applications.
IMHO, all that scenario worth it only if you are building corporate grade application. In most cases (and if you do REALLY need to collect files from clients) you have to install Apache + PHP server on the client side and make this guys to wait for request from YOUR remote php server. Without it, you can not get files from clients computers via browser without user input interactions. At least legally :)

How to Develop an Arbitrary Socket.IO Client that can Connect to a Socket.IO Server

I am trying to develop a socket.io application. It is just a simple application like the one on the Getting Started - Chat application tutorial in the Socket.IO webpage. But the problem is that, I do not want to have the socket.io server serve the client automatically, because I am planning to have a page (in PHP) have a script that can simultaneously be updated by data from a server in real-time using Socket.IO. I just want a certain client that can connect to the server and let them communicate, not a page served by the socket.io server.
Is this possible? Can you please give an idea on how can it be done. Thanks.
That chat tutorial is just a simple deployment where your own web page wants to connect back to the same server that the web page came from. That is not the only way to do it.
The socket.io client code can be served from anywhere. You can even link to a CDN and get it from there instead of from your own server.
And, likewise, the client can connect to any compatible server as long as the server is configured to accept a connection from your page.
If you're looking for how to connect to a different server, you just specify the URL of the desired host in io.connect() like this:
var socket = io.connect('http://www.example.com');

RTSP proxy/pipe to another server

I saw a question similar however the answers were irelevant to what I'm trying to achieve. Given that I have a local media server (for example Wowza) how can I use another server to pipe the requests to my local wowza server?
I'll expand. Given I have an application which sends live video feed to a webserver which runs apache server I'm looking for a script (prefebly php) to recieve this data and send it to another server which has wowza. (so basically act like a proxy)
ADVANCED:
I was also looking for a little more advanced solution if possible. If I open the webserver (send a request) I want it to start sending data to my local wowza server given it knows the right port

File sending from browser to a server which is not a web server

I want to send a file from my browser to a server which is not the server on which the site is hosted.The problem is the another server is not a web server.
Is it programmatically possible to send a file to different server without the involvement of host server? I do not want copy of the file I am uploading on my hosting server.
Sorry for not being clear on the first go. I hope this makes sense.
Note: I have the IP address of server. Implementation has to be done in a secure way.
Create a signed application to handle the upload.
One of the fundamental rules of browser sandboxing is that you don't let the browser communicate to a server other than the one which provided the website. This has been a rule for quite some time, and is done for security reasons.
The only way I know of to bypass this restriction is to use a signed application. This is possible in several languages including at least Flash and Java. Once you've signed your application with an authoritative source, then you can specify that your application is known to communicate with a third-party server and should be trusted to do so. The process of doing this will be different depending on the technology you choose.
The server to which you are sending the file needs to allow some sort of protocol in order to accept the file. You do not specify what that is, but these languages should be more than sufficient to implement whatever you need.
given that you have the necessary authentication of the secondary server you can
i'll explain using ftp, but there can be other socket related ways
1) upload the file to your server as usual, using $_FILE
2) use the ftp class in php to transfer the file to the remote host
Thanks all for valuable suggestions. I am opting for bit weird way but it seems the only feasible solution considering the current requirements of the project.
I am planning to install lite version of web server and php on the external server which can accept uploaded files through browser.
Our team has worked out this is the best solution we can consider as of now.
Thanks again to all for their suggestions.
This is done all the time with Firefox plugins, (youtube etc.). Does it have to be driven from your page source ? How stealthily do you want to do this ?
The other server should use a common protocol, SSH or ftp or NFS or CIFS.
In any case the user is going to have to agree with the plugin or the applet or a third party service (think punkbuster) running in the background.
BF4 runs in a browser window via a plugin and routinely sends data to servers other than the game server.

To use cURL FTP does both servers need the PHP cURL library installed?

I'm trying to wrap my brain about how to do this. We need to provide some files within a directory from our servers to our clients' servers via a PHP/Web interface using FTP. I've looked at the FTP capabilities built in to PHP and some custom classes, but someone suggested cURL might be a better option. We will have the FTP login credentials in our database for the application to access. With that information can we use cURL FTP capabilities to do the transfers, knowing our server has libcurl installed, but the clients servers may not? Do both servers have to have it for the FTP function to work?
Or am I completely going about this the wrong way, and have misunderstood how to use cURL and should be looking into an FTP PHP class?
libCURL is a library; it acts as the client.
Your clients need to be running a FTP server but do not need libCURL.
Just to make it super clear, there are 2 computers involved:
Your server, the one that's supposed to provide files to the client using the FTP protocol. That server does not need to have a web server (or PHP) running. The only thing it needs is an FTP server. It also needs to have permissions configured in such a way that there is an account that can access the files through FTP.
Your client's server, the one that's supposed to retrieve files from your server using the FTP protocol. That server needs to have PHP installed, with libCurl. The software on that server needs to access your server using the FTP protocol, providing the user credentials that you configured on your box.
Hope that helps.
It sounds like what you want to do is have the client connect to your PHP script & then push a button to start an FTP transfer that sends a file from your FTP server to their FTP server. If this is the case, then all you need is cURL on your server.

Categories