LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-25-2011, 02:53 AM   #1
athrin
Member
 
Registered: Mar 2011
Posts: 135

Rep: Reputation: 1
scp help


hi,

guys help me on how to use this
Code:
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
?>
i should put this code inside where?? sh file or php file? and what its mean by 'shell.example.com' ?

and also this.. where should i put this? in sh file or php file?
Code:
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

ssh2_scp_recv($connection, '/remote/filename', '/local/filename');
?>
 
Old 04-25-2011, 02:59 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

Could you give us some more information about what you're trying to accomplish? The code you posted is PHP code to connect to another server and copy / receive files using scp (over SSH connection). The host shell.example.com is just that, an example.

Kind regards,

Eric
 
Old 04-25-2011, 03:15 AM   #3
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
oh. i want to copy file to other server using web browser.
so i found this code and i dont know how to use it.
 
Old 04-25-2011, 03:20 AM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

Be careful to use code you don't understand. I imagine you've found that code here. You're aware you need a webserver like Apache for example, with PHP enabled and installed and besides that you'll need the functions you're calling in your code? If you have everything, including access to the remote server, you can try it out. Substitute the values in the script for the ones you use to connect and try it out. Watch log files for any errors.

Kind regards,

Eric
 
Old 04-25-2011, 03:34 AM   #5
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
now i only got the form and some php code to connect to other sh file.
haha.. sorry.. i dont quite understand on what you trying to said.
 
Old 04-25-2011, 03:39 AM   #6
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

If you don't understand what I said about needing a webserver, PHP, the functions, ... are you confident enough to get this set up? I think you'd better read some books to acquire the basic knowledge you need for this. Or what part of my post didn't you understand? The more detail you provide the better someone can help you. Tell me what part you don't understand and I'll try to explain.

Kind regards,

Eric
 
Old 04-25-2011, 03:50 AM   #7
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by EricTRA View Post
Hello,

Be careful to use code you don't understand. I imagine you've found that code here. You're aware you need a webserver like Apache for example, with PHP enabled and installed and besides that you'll need the functions you're calling in your code? If you have everything, including access to the remote server, you can try it out. Substitute the values in the script for the ones you use to connect and try it out. Watch log files for any errors.

Kind regards,

Eric
you said function to call code. function like what you mean? function to called .sh file or what? and about access to remote server?
 
Old 04-25-2011, 03:55 AM   #8
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

OK, in your original post you included:
Code:
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
?>
The words in bold are functions that are defined somewhere else in another PHP script or are complete PHP scripts you're calling. So if you only have the code you originally posted without those parts your script will do nothing (only give an error).

With access to remote server I mean that if you want to copy a file from one computer to another you need access to that remote machine in the form of a user/password combination (which you must provide in the script you posted where it says username and password). Without those you will not be allowed to copy files to the other machine. I hope that makes it a bit clearer.

Kind regards,

Eric
 
Old 04-25-2011, 04:02 AM   #9
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by EricTRA View Post
Hi,

OK, in your original post you included:
Code:
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
?>
The words in bold are functions that are defined somewhere else in another PHP script or are complete PHP scripts you're calling. So if you only have the code you originally posted without those parts your script will do nothing (only give an error).

With access to remote server I mean that if you want to copy a file from one computer to another you need access to that remote machine in the form of a user/password combination (which you must provide in the script you posted where it says username and password). Without those you will not be allowed to copy files to the other machine. I hope that makes it a bit clearer.

Kind regards,

Eric
oh now i understand.. that why i already created a form for the user to enter ip and password and also some php code for submit the input.
 
Old 04-25-2011, 04:31 AM   #10
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
err.. is this correct?? i set my ip addrs variable to ip1 and password to ip2.
Code:
<?php
if(isset($_POST["detailbtn"]))
{
$ip1=$_POST["ip1"];
$ip2=$_POST["ip2"];
system("/var/www/cgi-bin/script.sh $ip2");
}
?>
<?php
$connection = ssh2_connect('$ip1', 22);
ssh2_auth_password($connection, 'root', '$ip2');

ssh2_scp_send($connection, '/home/testing.sh', '/var/www/cgi-bin/testing.sh', 0644);
?>
regards,
athrin

Last edited by athrin; 04-25-2011 at 05:03 AM.
 
Old 04-25-2011, 04:52 AM   #11
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

I think you're misunderstanding the whole concept. Is the password you use to login on the remote server as root the value you store in $ip2?

Kind regards,

Eric
 
Old 04-25-2011, 05:02 AM   #12
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
misunderstanding whole concept? you mean my code is wrong? = =
yes.. i store pword with $ip2

Last edited by athrin; 04-25-2011 at 05:04 AM.
 
Old 04-25-2011, 05:09 AM   #13
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

OK, if you're storing your password in $ip2 then I just misunderstood. Assigning those strange names for a variable that will hold a password is confusing to all except to you. Have you tested your script and if so what are the results?

Kind regards,

Eric
 
Old 04-25-2011, 05:12 AM   #14
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
Talking

Quote:
Originally Posted by EricTRA View Post
Hi,

OK, if you're storing your password in $ip2 then I just misunderstood. Assigning those strange names for a variable that will hold a password is confusing to all except to you. Have you tested your script and if so what are the results?

Kind regards,

Eric
haha.. sorry.
i tried run it with web browser.. nothing copied.. i already check inside home
 
Old 04-25-2011, 05:21 AM   #15
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

You do have the function scripts right? And I get the impression you're using this script to copy locally right? Is your SSH server running and set up correctly?

Kind regards,

Eric
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help with scp 7mza Linux - Newbie 1 11-23-2009 10:36 AM
scp does not work and gives the following error message: scp: FATAL: Executing ssh1 i akay Linux - Networking 16 09-29-2008 12:41 AM
Scp B-Boy Linux - Newbie 2 07-07-2008 08:17 AM
scp help akhil.mud Programming 6 04-14-2008 09:47 PM
SCP how to the_rhino Linux - Newbie 5 02-11-2005 08:50 PM


All times are GMT -5. The time now is 07:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration