What I want to do
I want to upload
/download
a file via sftp
using php
.
The phpseclib-library
looks very promising.
What I already did
I changed my conposer.json to:
{
"require": {
"nicolab/php-ftp-client":"*",
"php-curl-class/php-curl-class":"*",
"phpseclib/phpseclib":"*"
}
}
Then i updated my directory. Composer installed the library in the vendor folder.
The Problem
The problem is that I am unable to create a new SFTP-Object
.
Fatal error: Class 'SFTP' not found in...
I also tried NET_SFTP
as classname but this didn't work also.
One thing I dont understand is why on, it states that the classname is NET_SFTP
when in the source its clearly called SFTP
.
Also autoload seems not to work.
I added echo "testline";
to the library to see if the file is loaded. Nothing happens if I use the autoloading. if i manually include the file, "testline"
is printed but the class is still not found.
My Code
Example one
<?php
include '/vendor/autoload.php';
$sftp = new SFTP('domain');
if (!$sftp->login('user', 'pass')) {
exit('Login Failed');
}
-> no echo
Example two:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib/phpseclib');
include('Net/SSH2.php');
include('Net/SFTP.php');
$sftp = new SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
-> echo
In both examples it cant find the class.
use phpseclib3\Net\SFTP;
– Positive