PHP and SCP


 
Thread Tools Search this Thread
Operating Systems Linux PHP and SCP
# 1  
Old 01-16-2008
PHP and SCP

How do I get PHP to use SCP?

I have tried using expect in a shell script and then passing it hostname, username and password.

The shell script works if it's run it from the command line (logged in as apache) but if I run it from a PHP script it doesn't work and I can't figure out why.

The web front end needs to:
- collect hostname, username, password
- log into remote machine
- transfer tar file from host machine to local machine
- expand tar file on local machine

Any suggestions would be greatly appreciated...

Thanks,
~Donavon
# 2  
Old 01-16-2008
I would suggest you use public keys instead of passwords for something like this. Then the user would not need to enter any username/password. Of course you front-end should be authenticated via some other means(ldap,file, etc..)

be very careful with your input parameters

check out PHP: Program Execution - Manual
# 3  
Old 01-16-2008
Public keys can't be used in this situation.
# 4  
Old 01-16-2008
my guess is that your script might be breaking because there is no terminal while running under apache and expect will not be able to read stdin.
# 5  
Old 01-16-2008
Quote:
Originally Posted by djlerman
How do I get PHP to use SCP?
this is just an example
Code:
<?php
$conn = ssh2_connect('ftp.server.com', 22);
ssh2_auth_password($conn 'user', 'pass');
ssh2_scp_send($conn, '/local/filename', '/remote/filename', 0644);
?>

# 6  
Old 01-16-2008
sweet. I did not realize PHP had an API for ssh. learn something new every day.
# 7  
Old 01-16-2008
Quote:
Originally Posted by frank_rizzo
sweet. I did not realize PHP had an API for ssh. learn something new every day.
It can be downloaded from PECL here
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Need help with scp

Hi, I am trying to do scp from server A to server B. But while doing the scp i am getting the following message. +-----------------------------------------------------------------+ | This system is for the use of authorized users only. | | Individuals using this computer system... (6 Replies)
Discussion started by: sidh_arth85
6 Replies

2. Shell Programming and Scripting

SCP

Hi All, Please help on the below command scp -r 'directory name'inrvgo@IP:/export/home/muthu/prod_12-09-2010 I am trying to copy a directory from one server to another server using the above command but its displaing the error (missing destination file) but the diectory was there in the... (1 Reply)
Discussion started by: thelakbe
1 Replies

3. AIX

scp

1. how to move files in a directory using scp ? 2. how to move the entire directory ? 3. Will the file and the directory permissions affect scp usage? (1 Reply)
Discussion started by: samsungsamsung
1 Replies

4. Shell Programming and Scripting

Is this possible with SCP?

I normally download a directory recursively using: scp -r <name>@host:<path> . This has worked fine. As everyone knows this will download all of the directory named in <path> and all of the sub directories. I would like to know if it is possible to not download a particular file if it... (5 Replies)
Discussion started by: cpabrego
5 Replies

5. UNIX for Advanced & Expert Users

help with scp

hi all in my script i was using the "scp" command to copy 2 files from a certain directory on server A to the same directory on another server B, but for some reason its only copying the first file in the directory. This is the frst time that i used the scp command,any ideas appreciated. thnks (5 Replies)
Discussion started by: bkan77
5 Replies

6. Shell Programming and Scripting

scp

hi can any one pls tell me how to copy a file from a remote host to the same remote host with a timestamp, i need to use only scp. thnks (4 Replies)
Discussion started by: bkan77
4 Replies

7. UNIX for Advanced & Expert Users

Scp

I am trying to transfer a 10g files using scp, but I am getting timeout errors is there anywhere that I can modify a config file or something to increase the time. (4 Replies)
Discussion started by: rbizzell
4 Replies

8. UNIX for Dummies Questions & Answers

scp

How do i use scp to copy a file from my home directory on a server I am logged into, to the computer I am using? I thought it would be something like: scp filename mycomp.company.org Thanks. (2 Replies)
Discussion started by: ignus7
2 Replies
Login or Register to Ask a Question