HeatWare.net header image
HeatWare.net
TwitterRSSEmail
  • Home
  • Windows
    • Windows 8
    • Windows 7
    • Windows Vista
    • Windows XP
  • Linux/Unix
  • Mac
  • Mobile
    • Android
    • iOS
    • Phones (Help / Resources)
  • Software / Programming
    • Free Software
    • Programming – General
    • PHP
    • Ruby/Rails
    • Quality Assurance (QA)
    • Software – General
    • Software Help
    • Databases
  • Cool Websites
  • Other
    • Deals & Bargains
    • News
    • Video Games
    • Hardware
    • Electronics
  • About

2 comments / February 20, 2009 / sood / Programming – PHP

How to SCP (Secure Copy) files using PHP5

This article will explain how to SCP (Secure Copy) files using PHP5. SCP is a secure method of copying files from one host to another using the SSH protocol. Here is a snippet of working code to help get you started!

$hostname = "target_host";
$username = "root";
$password = "password";
$sourceFile = "test.txt";
$targetFile = "/root/test.txt";
$connection = ssh2_connect($hostname, 22);
ssh2_auth_password($connection, $username, $password)
ssh2_scp_send($connection, $sourceFile, $targetFile, 0777);

This is a very simple script that does 3 things:

1) Connect to the host target_host

2) Authenticate with the host using root as the username and password for the password.

3) Copy the local file test.txt to /root/test.txt on the target machine.
Note:  0777 sets the permission on the target file so that it can be read/write/executed by anyone.

Digg This

Related Posts

  • How to call JavaScript function from PHP
  • Useful tips for PHP developers using MySQL
  • How to Find Files Owned by Group(s) in Linux
  • Find the number of files in a directory (Linux)
  • How to use tar to archive and extract files

PHP Programming

2 comments… add one
  1. Manny September 17, 2015, 5:11 pm

    I know this is an old post, but just in case…I am getting this error, and I have tried to install the dll and everything I have read about, on both flavours, 64 and 32, but no avail. I can’t get SSH to show up on phpinfo.

    Fatal error: Call to undefined function ssh2_connect()

    That is the error I am getting. I am running PHP 5.6.5

    Thank you

  2. Justin Estrada September 25, 2018, 11:58 am

    Hello I am also getting a “Fatal error: Call to undefined function ssh2_connect()” message.

    Running PHP 7 within a WordPress 4.9 environment.

Cancel reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Why You Should Consider Diving Apps
  • How to Buy a Smartphone that Fits Your Budget
  • How to Overcome Frustrating PDF Stress
  • Convert PDF to Word: Easy, Reliable and Quality Conversion
  • PDF to Excel App ­ – A New Way of Handling Tricky Documents

Recent Comments

  • Valarie Walter on Basic Troubleshooting Steps for your Cell Phone
  • John Mists on A Brief History of Android OS
  • syarif on PostgreSQL: How to reload config settings without restarting database
  • Raghu on How to SSH to a server using Ruby – Part I
  • francisco clemente on Basic Troubleshooting Steps for your Cell Phone

Tags

ACSLS Android Bargain Cell Phones Cool Software Cool Websites Databases Deals Ebooks Facebook Free Software G2x Galaxy S5 iOS iPhone Kindle LG Linux Linux/Unix Mac Mobile mysql Office OpenStack OS X PHP Postgres PostgreSQL ruby Samsung Galaxy S6 Shell Smartphones Sun T-Mobile Tips Tips & Tricks Ubuntu Unix Virtualization VMWare Windows Windows 7 Windows 8 Windows Vista Windows XP

Latest Tweet

Follow @HeatwaredotNet

SP
@HeatwaredotNet

  • Why You Should Consider Diving Apps https://t.co/Is41cdUv2I #diving-apps
    about 6 years ago

All Categories

Other Links

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2015 — HeatWare