Is there any way to have one server call and execute a script on another server? I have tried ftp_exec(), but the server does not support it. Here is what I am trying to do.
Server 1 creates and uploads a zip file to Server 2. Server 2 then unzips and extracts the file.
Currently I have scheduled cron jobs at alternating times, one on each server in order to do this. Ideally I would like Server 1 to be able to do everything, sending a message to sever 2 telling it to unzip and extract the uploaded file.
Is it possible to do something on Server 1, like exec(php ftp://user:password#server2/unzip.php) ?
Is it maybe possible using CURL?
FTP = File Transfer Protocol. It's not intended (and should never be used for) remote execution. If you need to trigger a remote script, use HTTP. It's easy enough to do
$stat = file_get_contents('http://example.com/unzip.php');
to invoke the remote PHP script to do the unzipping. If you need authentication on the URL, you can set up a stream or use CURL instead.
Does your sever support ssh or have you the ssh account?
You can run remote commands via ssh.
Related
This is a fairly simple question, yet I haven't been able to find a simple answer.
If I use curl on Server1 to access a PHP file on Server2, is the code in that file executed on Server2?
I have a script on a remote server that I need to be able to execute from my main server. The code should be executed on the remote server where the PHP file resides.
Yes, it is. Same as you'd enter that address to internet browser.
I've been trying to come up with a way to build an automated PHP transfer system between 2 servers. Server A : only ftp access; server B : ftp access and can run php scripts.
I want to copy all file in server A to a folder in server B;
Here is what I am trying to do :
1: function compress_each_ftp_folder_or_file_in_ftp_Backups_folder();
2: function delete each_ftp_folder_in_ftp_Backups_folder_after_successful_zipping();
3: function download_each_archive_in_ftp_Backups_folder();
4: function delete_each_archive_after_successful_download();
I have some scripts for step 2, 3 and 4 but nothing found on web that help me with step 1;
I found lot of codes to compress folders or files on local server, but I don't found any script that compress a whole folder on a remote ftp server.
I think it was the time to ask for a help. Thanks for helping me.
FTP protocol won't let you perform compression on the remote server so there's no direct way to accomplish the task.
In some cases some servers let you execute shell commands using SITE command. If you are lucky enough and this is supported on your server then you can call remote compression tool (zip would do) using SITE command with zip command invocation as a parameter. IF this is not supported by your server, then you need to use non-technical measures (eg. contact server admins for assistance).
I have application called unistat installed on my pc. I want to pass an argument from a web page and retrieve output from that program.
Is this possible?
How i can connect the website based on PHP to a remote desktop? ask to run .exe file by passing data and send output to specific location?
In order to access your local machine from the remote server, you're going to have to open up your router configuration settings and port forward all incoming port 80 traffic to your local web server's IP.
On your local machine, install PHP and set up an endpoint that runs the exec command, calling the .exe you wish to run.
You'd be wise to put this behind an authentication system, as it will be exposed to the www.
On the remote site, just fire a request off to the local machine's endpoint and the exec command will be run. Of course, if you have a dynamic IP, it's going to require constant maintenance.
See the following link about setting up custom protocols on Windows:
https://support.shotgunsoftware.com/entries/86754-launching-external-applications-using-custom-protocols-rock-instead-of-http
The idea would be that your web site could direct the browser to a special URL, i.e. unistat://my-data-goes-here and the application would be triggered with this data.
edit: better, MSDN link on the subject. http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx
edit2: Just realized you want to pipe the output from the EXE back to the webserver.... You may be better off building a browser extension. That, or writing a wrapper around unistat which can trap the output and submit it to a web service.
Using PHP, exec('php test.php'); will execute a separate PHP script on the command line.
What if test.php lives on another server, but within the same network? Can I specify that server's local IP address for the shell command to be run? What about a remote IP address? I could always install Apache on the second server and call the remote script via http, but would like to avoid that if possible.
Thanks, Brian
I can think of two options:
Use exec() to execute a program that connects to this other server and does whatever.
Set up a web service on the receiving server, and have the sending server send a request.
Regardless of what you choose to do, you'll need some setup on the receiving end, for the obvious reasons Dan Grossman pointed out.
I have a script on my one server and I want that script to create a file on another server of mine using PHP, NOT VIA FTP?
There are many ways to do this. I'd pick the first one myself because it's easiest to set up:
If you have PHP+Apache on another server, just call some script on the other server using file_get_contents with http URL as filename or use cURL if you need to POST file contents as well.
If the servers are in same network (LAN, VPN) you can use Windows shares/Samba or NFS to mount a remote directory to you local filesystem and simply write to file directly using fopen/fwrite functions
Use SSH via SCP or SFTP
PHP allows sending files across SSH - see the ssh2* family of functions, in particular ssh2_scp_send and ssh2_scp_recv.
I've never used them myself, but the infrastructure is there in Linux, just like SMB in Windows.
In general, FTP is the only regularly and easily available way (in PHP) to create a file on another server.
There are of course other protocols that enable you to create a file, but they all require installation of software on either one or both servers:
Samba (would enable access to the remote server through an absolute file path)
WebDaV (PHP client libraries available)
SCP (Finding a PHP client is probably going to be hard)
If both servers run PHP, it's probably the easiest to set up a PHP script on the remote server that accepts file data trough POST, and writes it out to a local file. Not a perfect solution, though, due to the limits usually imposed on POST uploads.
You could always use DAV, but it might require some configuration on the receiving server. There is also SSHFS, which lets you easily mount the remote directory locally over a SSH tunnel, or just use the ssh2_* family of functions as Andy Shellam suggested.
Really, there are lots of ways to accomplish this.