如何使用PHP进行SFTP? [英] How to SFTP with PHP?

查看:85
本文介绍了如何使用PHP进行SFTP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了许多用于Web FTP客户端的PHP脚本.我需要将SFTP客户端实现为PHP中的Web应用程序. PHP是否支持SFTP?我找不到任何样品. 有人可以帮我吗?

I have came across many PHP scripts for web FTP clients. I need to implement a SFTP client as a web application in PHP. Does PHP support for SFTP? I couldn't find any samples. Can anyone help me with this?

推荐答案

PHP具有ssh2流包装器(默认情况下处于禁用状态),因此您可以将sftp连接与任何支持流包装器的功能配合使用,方法是使用ssh2.sftp://作为协议

PHP has ssh2 stream wrappers (disabled by default), so you can use sftp connections with any function that supports stream wrappers by using ssh2.sftp:// for protocol, e.g.

file_get_contents('ssh2.sftp://user:pass@example.com:22/path/to/filename');

或-当还使用 ssh2扩展名

$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection);
$stream = fopen("ssh2.sftp://$sftp/path/to/file", 'r');

请参见 http://php.net/manual/en/wrappers.ssh2.php

在旁注中,已经有很多关于此主题的问题:

On a side note, there is also quite a bunch of questions about this topic already:

这篇关于如何使用PHP进行SFTP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆