0

I'm using PHP_SSH2 version 1.1.2 (and phpseclib version 1.0.11) and when trying to upload files, I get this error:

PHP Fatal error: Uncaught error: Call to undefined method Net_SSH2::put()

Here is the code I'm using:

require 'Net/SSH2.php';
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);

$connection = new Net_SSH2($ftp_server);
if(!$connection->login($ftp_user_name, $ftp_user_pass)){ 
    die("FTP connection has failed!\nAttempted to connect to $ftp_server for user $ftp_user_name"); 
}

$source_file = 'filename.txt';
$destination_file = $source_file;
$upload = $connection->put($destination_file, $source_file, NET_SFTP_LOCAL_FILE);

if (!$upload) die("FTP upload of $source_file has failed!");

I can connect to the server okay (so login() works), but put() doesn't?

kurdtpage
  • 3,142
  • 1
  • 24
  • 24
  • Are you trying to use SFTP or FTP? In the case of SFTP, you'd want SFTP not SSH2. SFTP uses the SSH protocol, not FTP protocol, but phpseclib still has a separate class for it. – Devon Bessemer Jun 22 '18 at 03:03

1 Answers1

1

Net_SSH2 does not have a put method. You'd need to use Net_SFTP to perform SFTP actions on the SSH server.

http://phpseclib.sourceforge.net/sftp/examples.html#put

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95