Segmentation error on fopen using sftp and ssh2

I have a php system running on AWS and a class that uploads an xlsx file to an external server using shh2 and sftp . This code worked fine until the last update of the aws package openssh-clients-6.6.1p1-31.62 and openssh-server-6.6.1p1-31.62 , by then I have segfault during fopen . Fopen creates the file on an external server. Here is the code:

$stream = @fopen("ssh2.sftp://$this->sftp$remote_file", 'w');

Then I use $ stream to write the content, but the code stops at fopen bacause segfault. I don’t know anything about this problem, I think the problem is in the new opnessh update, because the php code does not change. Any idea?

+5
source share
4 answers

Found the answer here on StackOverflow: fooobar.com/questions/1663605 / ...

It looks like with this PHP update you should surround your part of the host (result ssh2_sftp()) with intval():

$handle = opendir("ssh2.sftp://".intval($sftp)."/path/to/directory");

In my case, it opendirwas instead fopen, but the solution is the same.

+17
source

In our case, intval () does not solve the segmentation problem. However, a change in call format was made:

fopen("ssh2.sftp://{$username}:{$password}@{$host}:{$port}/{$absolutePath}/{$filename}", 'w');
+3
source

, PHP (. : [2016-12-15 09:47 UTC] by ovoelker at wavecon dot de)

  • php5-dev pecl
  • ssh2 pecl.
  • apache
0

intval($sftp) " " intval($sftp) ssh2_disconnect(). SFTP- SSH2- unset($sftp) $sftp = null. :

if (!$ssh2_connection = ssh2_connect($host, $port)) {
    die("Failed to connect\n");
}
if (!ssh2_auth_password($ssh2_connection, $username, $password)) {
    die("Failed to login\n");
}
if (!$sftp_connection = ssh2_sftp($ssh2_connection)) {
    die("Failed to open SFTP session\n");
}
if (!$fh = fopen("ssh2.sftp://".intval($sftp_connection).$path, 'r')) {
    die("Failed to open file\n");
}
while (($s = fgets($fh)) !== false) {
    echo $s;
}
fclose($fh);
unset($sftp_connection);
if (!ssh2_disconnect($ssh2_connection)) {
    die("Failed to disconnect\n");
}

PS " " - :

php: channel.c: 2570: _libssh2_channel_free: "" .

.

0

Source: https://habr.com/ru/post/1663604/


All Articles