I want to copy a zip file from remote to my local system using SCP.
I have a php file where i use php function exec();
if i run upload.php like http://www.abc.com/upload.php.
The zip file should copy to my local linux folder my path is
/var/www/html/mydirectory/
How can i do this ?
You can use PHP's PECL ssh2 extension that provides ssh2_scp_send.
In order to automate any ssh connection like scp you have to set up a pair of auth keys.
This will allow your remote computer to connect to your local computer with out a password prompt. A simple google search will show you how to set this up. The resource I used is http://linuxproblem.org/art_9.html.
The auth key allow the computers to recognize each other and handshake with out a user prompt but remember doing this does provide free ssh access from your remote location to your home computer without a password, so handle permissions carefully.
A better way than an scp if you don't need encryption is to set up a wget on your local computer to grab off your remote computer's web dir.
To me, it seems like you are asking how to download a zip file from your remote web server. In that case, you could simply give the browser the direct path to the zip and let it download it. You can't push a file from the server to the local machine with SCP. Use HTTPS if you're concerned about security. If the zip file is outside of the web directory, you can use PHP to read the file (assuming apache has access to it) and then output it to the browser.
Related
I have been searching for an answer to this for a couple of hours with no clear answer.
I normally write .php scripts which do helpful administrative tasks on my website. I upload them to an ftp folder, and run them from my browser when I need them.
Unlike what I a used to, I am trying to run a script (someone else wrote it) to and have been told that I cannot do so from the browser and I need to do it from the command line. Basically everything is set up, but I cannot push to go button and run the script.
Any ideas? I have php installed on my local computer and can run scripts locally from browser and command line, but I do not know how to do the same for the scripts on my website.
I don't know if this helps, but my server is apache and runs off php version 5.3.3
Download Putty, from http://www.putty.org/
Run it
In "host" write your domain, and click on Open
When the black window open, it will ask you for your credentials:
Write your ssh credentials, if you have. If you dont, try with the ftp user and password.
If it doesn't work...get into your host control panel, and find out how to create an SFTP, or SSH user. If you can't find anything, contact support asking how to create that kind of user. When you have it
After you login, your are inside your server, and you can move around, as you would in linux. If you dont know the basics, find a good tutorial. Or just relay in:
ls : list the files and directories
pwd : know in what directory you are
cd DIRNAME : change to other directory inside de current one
cd .. : change to the parent directory
When you are in the directory where your script lives, just execute:
php yourscrip.php
if its a php script
php path_to_script.php
else
/path/to/script
If its the second option you will need to chmod +x /path/to/script first
These should all be run from a ssh session (or any other way of accessing a command line on the machine running the website)
to ssh to a sever use putty if on windows. Your host will be able to give extra details on how to access
So I had to write a script that will separate certain images on a network file server and back them up preserving the file structure. To do this, I am mounting the file server as a folder on my linux box where the script will be running. The file server is a windows box.
The file server was mounted like this:
mount -t cifs //xxx.xxx.xxx.xxx/pictures$ -o username=imageuser,password=pa$$word images
If I run a copy command like this:
cp images/somefolder/subfolder/someimage.jpg images/differentfolder/subfolder/someimage.jpg
My question is this:
Will "someimage.jpg" be simply be copied from one location to the other on the windows machine, or will the image be downloaded to the linux box over the network and then uploaded to the new location on the windows machine?
Edit: If the file will be round-tripped - I would like to know how to do it without that or at least to be pointed in the right direction where I can read up on a way to do it.
Neither cp nor the smb protocol are smart enough to realize that the source + destination of the file are on the same remote server. cp will simply do its usual thing and slurp all the data from the source file (copying it to the client machine), then spit it back out in the target file on the server. So yes, it'll be a round-trip through the client.
A better solution for this sort of thing is using an SSH remote command, turning it into a purely server-side operation:
ssh imageuser#x.x.x.x 'cp sourcefile targetfile'
You can still keep the fileserver mounted on your local machine to actually see what files you're dealing with, but do all the file copy/move operations via the ssh commands for efficiency. Since the server is a Windows machine, you'll probably have to install cygwin and get an ssh server running.
I'm using flare to decompile a flash movie. I need to do it via PHP. User visits PHP script, it decompiles the flash movie.
Here is how the files are set up on my web host:
index.php:
<?php
error_reporting(-1);
echo shell_exec('./flare movie.swf');
?>
Flare is supposed to create a file named movie.flr once the script runs, but there is no such file. I am thinking my shell_exec is wrong.
phpinfo() - http://zachafer.com/phpinfo.php
You're trying to execute the wrong file.
flare.tgz is an archive (not executable) containing the flare binary (executable).
Unpack it with an archiver tool like winrar on windows or tar on linux (tar xvf flare.tgz).
Inside the archive, you will find a file named flare. Try with this one and it might work if your host provider allow the shell_exec() function calls.
You can't execute a .tgz file directly! You need to unpack the executable before you can run it.
This function is disabled when PHP is running in safe mode... check it or ask your host provider about it
I think flare.tgz is not an executable but a .tar.gz file (it's like a zip file, but it is another format).
You have to unpack it first !
WAMP server
PHP fopen function needs to open file in shared folder //server/folder1/file1.txt
php has SYSTEM user permisions, but shared folder is visible only for userX/password
how can i open this remote file inside php script?
You can specify the username and password in the path: //user:password#server/folder1/file1.txt
I had the exact same problem and Sjoerd's answer didn't work for me on Windows.
I wrote a mounting function in PHP which basically execs:
net use "\\smbserver\share" /user:"myuser" "mypassword" /persistent:no
Then you can normally access paths like \\smbserver\share/path/file.
This works for all functions specified in the options table for file wrappers:
Allows Reading
Allows Writing
Allows Appending
Allows Simultaneous Reading and Writing
Supports stat()
Supports unlink()
Supports rename()
Supports mkdir()
Supports rmdir()
This works perfectly stable on remote shares but didn't work for me when I used localhost with apache as SYSTEM.
Don't forget to unmount afterwards by execing:
net use "\\smbserver\share" /delete /yes
I hope this helps.
For example, i want a file has permission of 644 automatically when i uploaded it to my linux host, before upload, it is under windows. How could i do this?
Btw, i use Filezilla for upload
Updated: Before post this question, actually, i ever thought it is impossible too. But, as i has many wordpress sites, i remembered that i never need to set permission for wordpress files. So i did an experiment,
dowload a new wordpress package, zip format (under windows)
uploaded it to my linux host,
unarchive
check permissions of these files
I saw all files had their permission naturely right, some 644, some 755, exactly as described in wordpress document
I think this is not possible in most cases.
Could you give more information on how you upload? FTP, SFTP, SMB? :-)
For example for FTP you could configure the FTP server in order to give all new files the 644 umask (see this example for ProFTPd).
For SFTP, the client might be able to change the permissions after the upload, because it has SSH access, after all.
You can't. The permission is not written in the file itself, but rather in the filesystem. So it has to be done once the file has being uploaded.
Assuming that you are using FTP to upload the files, better FTP clients (FileZilla) will allow you to set the permissions IF THE SERVER is setup to allow the FTP client to set it.
As far as "default settings", 644 is typically the default already for files. This again is set by the server. I would assume that there is an FTP client out there that will auto set it for every file, but I don't know for sure. If you go monkeying with permissions, remember that directories are 755, not 644, and it is possible that the server could let you remove your own access to the file.
First, what username owns the files? What username do you connect as when you upload?
What is that user's default umask setting?
So you could use the Windows FTP command "quote" which lets you send arbitrary commands to the FTP server.
Assuming your Linux FTP server supports SITE UMASK...
e.g. ftp> quote SITE UMASK 111
This would be equivalent to doing: chmod 666 * on the Linux command line but via FTP on Windows.