how to connect to remote server usin ssh

Reply

Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

how to connect to remote server usin ssh

 
0
  #1
Dec 1st, 2008
how to conecct remote server by using ssh in php
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: how to connect to remote server usin ssh

 
0
  #2
Dec 1st, 2008
For that you will PHP bindings for libssh2.
You can check out one of them here or here.

Note both the links refer to the same extension.
Last edited by stephen84s; Dec 1st, 2008 at 8:29 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

Re: how to connect to remote server usin ssh

 
0
  #3
Dec 1st, 2008
i am sending my file by using ftp_connect sucessfully. but now the server details are changed .i need to send my data bu ssh.
it is new and difficult for .
if can u explain to me the main steps.......
i will be very thankfull to u for your time.
thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: how to connect to remote server usin ssh

 
0
  #4
Dec 2nd, 2008
I am not going to spoon feed you the exact steps and I do not prefer anyone bugging me for help via PM,
See the following, page it was already present in my earlier link, if you had cared yo take the time to read it, you would have found it out yourself.
http://in.php.net/manual/en/function.ssh2-scp-send.php
Last edited by stephen84s; Dec 2nd, 2008 at 9:55 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

Re: how to connect to remote server usin ssh

 
0
  #5
Dec 3rd, 2008
Thanks my friend
it is not about for something i ask you to give me any code.
i just want to understand,
how i can work on ssh.
it new for me.
i already work on it from last week, i gather alot of data about it but still i am confused.
i think i will tell u the problom i have,
my server is ssh.
through ftp i am accessing the the server and i can read file over there, but when i am trying to upload file then i have the following error,
Starting FTP! in/ may already exist
array(5) { [0]=> string(3) "in:" [1]=> string(7) "total 0" [2]=> string(0) "" [3]=> string(4) "out:" [4]=> string(7) "total 0" } . .. su86.zip
Warning: ftp_fput() [function.ftp-fput]: Access is denied. in G:\WEBROOT\aa\ftpcopy_ver2.php on line 35
There was a problem while uploading su86.zip
Warning: ftp_site() [function.ftp-site]: su86.zip: No such file or directory. in G:\WEBROOT\aa\ftpcopy_ver2.php on line 46
FTP completed! PHP Warning: ftp_fput() [function.ftp-fput]: Access is denied. in G:\WEBROOT\aa\ftpcopy_ver2.php on line 35 PHP Warning: ftp_site() [function.ftp-site]: su86.zip: No such file or directory. in G:\WEBROOT\aa\ftpcopy_ver2.php on line 46



if you like then i am sending my code as well check it if you want, i am not forcing you,
  1. <?php
  2. function rec_copy ($source_path, $destination_path, $con){
  3. //print "hello\n";
  4. if (@ftp_mkdir($con, $destination_path)) {
  5. echo "successfully created $destination_path\n";
  6. } else {
  7. echo "$destination_path may already exist\n";
  8. }
  9.  
  10. ftp_site($con, 'CHMOD 0777 '.$destination_path); //set writeable
  11.  
  12. $buff = ftp_rawlist($con, ".");
  13.  
  14. echo "<br/>";
  15. var_dump($buff);
  16.  
  17.  
  18. ftp_chdir($con,$destination_path); //move to remote directory
  19.  
  20. if (is_dir($source_path)) { //check for local directory
  21. chdir($source_path); //change to local directory
  22. $handle=opendir('.'); //open current directory
  23. while (($file = readdir($handle))!==false) { //read files
  24. echo $file . "\n";
  25. if (($file != ".") && ($file != "..")) { //if not an unwated file
  26. if (is_dir($file)) { //if is a directory
  27. if($file != "propertyimages") { //here i am restricting the folder name 'propertyimages' from being copied to remote server. -- VK
  28. rec_copy ($source_path."/".$file, $file, $con); //call this function on new directory
  29. chdir($source_path); //change to server local directory because after calling this function the ftp handle would be inside said directory
  30. ftp_cdup($con); //change to parent directory on server
  31. }
  32. }
  33. if (is_file($file)) { //if is a file
  34. $fp = fopen($file,"r"); //open local file for reading
  35. if (ftp_fput ($con, $file, $fp,FTP_BINARY)) {
  36. // echo "successfully uploaded $file\n";
  37. fclose($fp);
  38. $command ="echo Y| cacls \"" . realpath($source_path) . "\\" . $file."\" /G administrators:F";
  39. //echo $command . "\n";
  40. $e = exec($command) . "\n";
  41. unlink($file);
  42. } else {
  43. echo "There was a problem while uploading $file\n";
  44. }
  45.  
  46. ftp_site($con, 'CHMOD 0755 '.$file); //set permissions
  47. }
  48. }
  49. }
  50. closedir($handle);
  51. }
  52. }
  53.  
  54. print "Starting FTP!\n";
  55.  
  56. $con = ftp_connect("bbbbbbbbbbbbbbbbbbbbbbbb);
  57.  
  58. //$con = ftp_ssl_connect("bbbbbbbbbbbbbbbbbbbbbbb);
  59.  
  60. // make a FTP connection --VK
  61.  
  62. $login_result = ftp_login($con,"nnnnnnnnnnnnnnnnnnnnnnnnnnnnn"); // login
  63. //$con =ftp_connect("bbbbbbbbbbbbbbbbbbbbbbbbb);
  64. //$login_result=ftp_login($con,"bbbbbbbbbbbbbbbbbbbbbbb");
  65.  
  66. ftp_pasv($con,true);
  67. $rootpath = "in"; // this is the root path for the remote server-- VK
  68. //$rootpat,,,,,,,,,,,,,,,,,,,,,,,,,,/";
  69. ftp_chdir($con,$rootpath);
  70. $sourcepath = realpath("nnnnnnnnnnnnnnnnnnnnn"); // this is the physical path of the source directory. actually u can also use the relative path. -- VK
  71. $destination_dir_name = "in/"; // this directory name will only change the top most directory and not the inner one -- VK
  72. rec_copy ($sourcepath, $destination_dir_name, $con); //copy files
  73. if (function_exists("ftp_close")){ //close connection
  74. ftp_close($con);
  75. }
  76.  
  77. print "FTP completed!\n";
  78. ?>
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

Re: how to connect to remote server usin ssh

 
0
  #6
Dec 3rd, 2008
This code and problom is here ,Anyone Who wish to contribute his knowlege then he can reply to this problom, otherwise for all those people who are roud then i am in advance asking them, please dont disturb me with your roud advoices,
many thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,193
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: how to connect to remote server usin ssh

 
0
  #7
Dec 3rd, 2008
There was no rude advice from anyone as far as I can see. You asked general question and you got general answer. You asked little more specific, the answer was given in that way.
If you want to get maximum support or help you better provide everything what you got.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: how to connect to remote server usin ssh

 
0
  #8
Dec 4th, 2008
Originally Posted by asifkamalzahid View Post
This code and problom is here ,Anyone Who wish to contribute his knowlege then he can reply to this problom, otherwise for all those people who are roud then i am in advance asking them, please dont disturb me with your roud advoices,
many thanks
You wanted to send a file via SSH and I gave you the link to it, Unfortunately you still couldn't figure it out so I gave you the exact link to the page where the example was mentioned, Now do you want me to do the coding also for you. Also the code you have pasted here is for FTP connectivity not SSH, so definitely it shouldn't work.
Have you even gone through the examples mentioned in my previous link ??? Here I will paste the code for you:-
  1. <?php
  2. $connection = ssh2_connect('shell.example.com', 22);
  3. ssh2_auth_password($connection, 'username', 'password');
  4.  
  5. ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
  6. ?>

Also the same page contains an example for sftp :-
  1. <?php
  2. $srcFile = '/var/tmp/dir1/file_to_send.txt';
  3. $dstFile = '/var/tmp/dir2/file_received.txt';
  4.  
  5. // Create connection the the remote host
  6. $conn = ssh2_connect('my.server.com', 22);
  7.  
  8. // Create SFTP session
  9. $sftp = ssh2_sftp($conn);
  10.  
  11. $sftpStream = @fopen('ssh2.sftp://'.$sftp.$dstFile, 'w');
  12.  
  13. try {
  14.  
  15. if (!$sftpStream) {
  16. throw new Exception("Could not open remote file: $dstFile");
  17. }
  18.  
  19. $data_to_send = @file_get_contents($srcFile);
  20.  
  21. if ($data_to_send === false) {
  22. throw new Exception("Could not open local file: $srcFile.");
  23. }
  24.  
  25. if (@fwrite($sftpStream, $data_to_send) === false) {
  26. throw new Exception("Could not send data from file: $srcFile.");
  27. }
  28.  
  29. fclose($sftpStream);
  30.  
  31. } catch (Exception $e) {
  32. error_log('Exception: ' . $e->getMessage());
  33. fclose($sftpStream);
  34. }
  35. ?>
I bet you have not even read it else you wouldn't have needed to post again. Also if you cannot understand the examples there on your own, I suggest you hire a programmer who does know something about PHP and SSH.

BTW I think you are the one who first broke the community rules and begged me for help via PM. If you want help then learn to control your tongue and don't expect anyone else to do your coding for you.

Sorry Peter I couldn't control my rage on this one.
Last edited by stephen84s; Dec 4th, 2008 at 2:38 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 17
Reputation: asifkamalzahid is an unknown quantity at this point 
Solved Threads: 0
asifkamalzahid asifkamalzahid is offline Offline
Newbie Poster

Re: how to connect to remote server usin ssh

 
0
  #9
Dec 4th, 2008
You are good person, but a bit angry, i realy dont know why?
anyway dont mind.
be happy.
i just wanted to understand how to establish a connection between two servers. i did it by ftp. now i was looking for secure connection.just for learning i did it.
if it is not possible then no worry, its ok.it is not important.
how you take my words that i am bagging you for help. this is the word which is problamic. dont use it, becouse it will make you angry and tense. be happy and enjoy your php buddy.
have very good day and nights.
bye bye for
ever.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC