| | |
how to connect to remote server usin ssh
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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 ?"
"How to ask questions the smart way ?"
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
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 ?"
"How to ask questions the smart way ?"
•
•
Join Date: Nov 2008
Posts: 17
Reputation:
Solved Threads: 0
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,
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,
PHP Syntax (Toggle Plain Text)
<?php function rec_copy ($source_path, $destination_path, $con){ //print "hello\n"; if (@ftp_mkdir($con, $destination_path)) { echo "successfully created $destination_path\n"; } else { echo "$destination_path may already exist\n"; } ftp_site($con, 'CHMOD 0777 '.$destination_path); //set writeable $buff = ftp_rawlist($con, "."); echo "<br/>"; var_dump($buff); ftp_chdir($con,$destination_path); //move to remote directory if (is_dir($source_path)) { //check for local directory chdir($source_path); //change to local directory $handle=opendir('.'); //open current directory while (($file = readdir($handle))!==false) { //read files echo $file . "\n"; if (($file != ".") && ($file != "..")) { //if not an unwated file if (is_dir($file)) { //if is a directory if($file != "propertyimages") { //here i am restricting the folder name 'propertyimages' from being copied to remote server. -- VK rec_copy ($source_path."/".$file, $file, $con); //call this function on new directory chdir($source_path); //change to server local directory because after calling this function the ftp handle would be inside said directory ftp_cdup($con); //change to parent directory on server } } if (is_file($file)) { //if is a file $fp = fopen($file,"r"); //open local file for reading if (ftp_fput ($con, $file, $fp,FTP_BINARY)) { // echo "successfully uploaded $file\n"; fclose($fp); $command ="echo Y| cacls \"" . realpath($source_path) . "\\" . $file."\" /G administrators:F"; //echo $command . "\n"; $e = exec($command) . "\n"; unlink($file); } else { echo "There was a problem while uploading $file\n"; } ftp_site($con, 'CHMOD 0755 '.$file); //set permissions } } } closedir($handle); } } print "Starting FTP!\n"; $con = ftp_connect("bbbbbbbbbbbbbbbbbbbbbbbb); //$con = ftp_ssl_connect("bbbbbbbbbbbbbbbbbbbbbbb); // make a FTP connection --VK $login_result = ftp_login($con,"nnnnnnnnnnnnnnnnnnnnnnnnnnnnn"); // login //$con =ftp_connect("bbbbbbbbbbbbbbbbbbbbbbbbb); //$login_result=ftp_login($con,"bbbbbbbbbbbbbbbbbbbbbbb"); ftp_pasv($con,true); $rootpath = "in"; // this is the root path for the remote server-- VK //$rootpat,,,,,,,,,,,,,,,,,,,,,,,,,,/"; ftp_chdir($con,$rootpath); $sourcepath = realpath("nnnnnnnnnnnnnnnnnnnnn"); // this is the physical path of the source directory. actually u can also use the relative path. -- VK $destination_dir_name = "in/"; // this directory name will only change the top most directory and not the inner one -- VK rec_copy ($sourcepath, $destination_dir_name, $con); //copy files if (function_exists("ftp_close")){ //close connection ftp_close($con); } print "FTP completed!\n"; ?>
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.
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
•
•
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
Have you even gone through the examples mentioned in my previous link ??? Here I will paste the code for you:-
php Syntax (Toggle Plain Text)
<?php $connection = ssh2_connect('shell.example.com', 22); ssh2_auth_password($connection, 'username', 'password'); ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644); ?>
Also the same page contains an example for sftp :-
php Syntax (Toggle Plain Text)
<?php $srcFile = '/var/tmp/dir1/file_to_send.txt'; $dstFile = '/var/tmp/dir2/file_received.txt'; // Create connection the the remote host $conn = ssh2_connect('my.server.com', 22); // Create SFTP session $sftp = ssh2_sftp($conn); $sftpStream = @fopen('ssh2.sftp://'.$sftp.$dstFile, 'w'); try { if (!$sftpStream) { throw new Exception("Could not open remote file: $dstFile"); } $data_to_send = @file_get_contents($srcFile); if ($data_to_send === false) { throw new Exception("Could not open local file: $srcFile."); } if (@fwrite($sftpStream, $data_to_send) === false) { throw new Exception("Could not send data from file: $srcFile."); } fclose($sftpStream); } catch (Exception $e) { error_log('Exception: ' . $e->getMessage()); fclose($sftpStream); } ?>
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 ?"
"How to ask questions the smart way ?"
•
•
Join Date: Nov 2008
Posts: 17
Reputation:
Solved Threads: 0
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.
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.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Dynamic Title Generation using PHP and MySql
- Next Thread: PHP extension querie! .php?id=2
| Thread Tools | Search this Thread |
apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl data database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip javascript joomla limit link links login mail match md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion remote script search searchbox server session sessions sms smtp soap source space sql strip_tags survey syntax system table tutorial undefined update upload url validator variable video virus votedown web website window.onbeforeunload=closeme; xml youtube






