compress a whole folder on remote ftp server with php - php

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).

Related

Should I use PHP readfile() or SFTP connection to download file from my server through a web app?

I was thinking about replacing all my PHP readfile() function calls into SFTP connections request to download files from my server.
Is this safer ?
Note : my files are on the same server as the web app, so is this useless to pass through SFTP ?
Thank you for your concern.
"If they're on the same server, you don't necessary need SFTP. That's like using a FTP to browse files locally on your computer – Cid 29 mins ago"

Write code locally, send to server

I'm trying to configure my web server and I'm a complete beginner. Now everything is working quite fine. I want to write some php files. But I only have unix command line access to the server and vim or nano are not really convenient for writing lines of codes.
So the question is :
- Is there a unix command line php editor i can "apt-get install" on my debian server ?
- Is there a proper way of writing files on my computer and then commit them to the server ?
Here I'm looking for an easy solution... As I don't have much knowledge about the subject !
Thanks !
Yes, typically whoever is hosting your server will give you some kind of facility for uploading for files: FTP, SCP, etc. If someone else is running your server for you (e.g., a web host) you should contact them to find out what options you have. If you are administrating over the server yourself, you will need to install some kind of file transfer server on it. FTP would be the obvious choice, but not necessarily the best, especially if you have to connect to it over the public internet (FTP is not encrypted by default, so your file contents and even your login details will be sent in clear text over the network). If you are using SSH (e.g., PuTTY) to connect to your server, you should be able to use pscp to copy files securely.
But for what it's worth, Vim is super convenient for writing lines of code, once you know how to use it. Vim is a programmer's text editor, it's got loads of features that make writing lines of code easy.

Create .exe file in php with mysql database

i have developed in-house software for hotel management system using PHP/MYSQL. Our Client wants Software in .exe format and used in desktop. i use various softwares for .exe conversion but it only support php but i want's to connect with MySQL Database. Please anyone can help to create .exe conversion with MySQL Database..
Download PHP Desktop Chrome.
Copy all your code from site directory to Phpdesktopchrome/www directory.
Run Phpdesktopchrome.exe, it will execute like a browser with PHP compiler.
Download Innosetup Software for make exe file.
Install and run Innosetup and select Phpdesktop chrome files to create a EXE file in Option.
Install wampserver in client system with database import.
Enjoy.
There are many compliers available on web by which you can create EXE in PHP.
This program runs through dos and windows only... :) so this is good news for windows user
First Download zip from Here.
Now unzip it and open Command prompt and then go to its directory location.
Start -> run then type ‘cmd’
Use the “cd..” command to change directory.
Place PHP script to be compiled next to bamcompile.exe place it in same directory.
In the cmd prompt, at that directory, type:
bamcompile test.php
variations:
bamcompile -c test.php gives compression.
-e:something.dll allows a DLL to be embedded
Ready made examples are given in Zipped files which you have downloaded,just try it out.
Another application wapache is also there but i dont know much about it.
DOWNLOAD WAMP server from wampserver.com.
its very good for offline use server for desktop, then just copy and paste you script abd .sql file into it. and you are Done.
If your client using highspeed interenet then they can connect the server to online. but they need super computer for more traffic, another option is LAN.
If the program is for office use and no need to connect a lot of computer and internet then use LAN and WAMP.
------ Another possible you can use --------
Install WAMP then copy then .exe file "click start button > all program > and paste into startup folder". server will run automatic windows OS start or restart but it take 2-3 min. (green light)
go to wamp folder > www > make a folder for your program then paste your script.
open any browser then in address bar type "localhost or 127.0.0.1 (localhost IP for offline)" , scroll down and you will see "Your Projects" and under of this you will see your folder which you had create into wamp server > www folder. click on it and here you gooooo....
Now your client can do work with your script. Bookmark it and also create a shortcut into desktop for direct use.
Hope this may help you. thank you.
If you are getting any problem to do this work, then email me here - (krishnabiker#yahoo.com)
I think you should just convince your client not to use a .exe installer. It makes no sense.
You could have an installer that installs a local webserver and a local MySQL, and then opens a web browser and browses the local webserver. This would work, but it means your application runs on only one machine, and can't be used by two people.
On the other hand, you could install an application that talks to a central MySQL database, hosted on the LAN. But then why not install the entire application (webserver, MySQL etc) on the LAN, and have the clients access it across the LAN as a web application? Still no reason for a local install.
I would suggest:
See if you can persuade your client to move to an entirely web-hosted solution. Emphasize how easy updates are - from one central location, not from each machine; or
See if you client won't be happy with a .exe that installs a link to a URL (on the LAN).
VERY SHORT ANSWER: NOT POSSIBLE
Tell your client that it is a client-server application not a desktop app.
One idea is to have portable PHP/MYSQL/APACHE that can be stored in a CD or used and create an autorun fro it..
Tell your client you can do better than that, you can create a batch file for his use!
Then create a program.bat file with one line that runs the php (should be something like "php ").
:)
We need to bundle your project files in MSI ( windows installer ) along with PHP frameworks, MySQL and Apache.
Everything can be included in a single MSI file or you can keep server part in one MSI (PHP framework+Apache framework+ MySQL) and your Project file along with Yiiframework in another MSI.
I already made server part MSI in order to create one of my previous web project. In that project i had to configure Mysql DB (my.ini) and Apache configuration file (.conf). It worked fine.
For a desktop application I recommend that you change your database settings (if you can) and switch to SQLite3 DB. They are portable files and does not need a database server to run.
Use http://www.usbwebserver.com/ and from a stick or an CD/DVD you will be able to run your application. It is a portable version similar to W

Alternative to ftp_exec()?

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.

Creating a file on another server using PHP file functionality

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.

Categories