来自 PHP 内部的 SFTP

2022-01-09 00:00:00 sftp ftp curl php

我正在构建一个网络应用程序,除其他事项外,它还需要连接到 FTP 服务器以下载或上传文件.该应用程序是用 PHP 编写的,并且托管在 Linux 服务器上.

I'm in the process of building an web app that will, besides other things, need to connect to a FTP server to download or upload files. The application is written in PHP and it's hosted on a Linux server.

我想知道是否也可以提供对 SFTP 服务器的支持,但是在 Google 上进行了一些快速搜索后,似乎这并不是那么简单.

What I was wondering is whether or not it would be possible to also provide support for SFTP servers, but after some quick searches on Google it seems that this is not all that simple.

所以,问题是:在 PHP 中使用 SFTP 的最佳方式是什么?是否有一个类可以同时提供对 FTP 和 SFTP 的支持,以便两者都可以使用相同的功能?

So, the question is: What would be the best way to use SFTP from within PHP? Is there a class that could also provide support for FTP as well as SFTP so that same functions could be used for both?

推荐答案

是的,你可以用 卷曲.要从 FTP 切换到 SFTP,您只需将协议选项形式的 CURLPROTO_FTP 更改为 CURLPROTO_SFTP.

Yes, you can do that with cURL. To switch from FTP to SFTP all you have to do is to change protocol option form CURLPROTO_FTP to CURLPROTO_SFTP.

cURL 支持以下协议:HTTP、HTTPS、FTP、FTPS、SCP、SFTP、TELNET、LDAP、LDAPS、DICT、FILE、TFTP.

cURL supports following protocols: HTTP, HTTPS , FTP, FTPS, SCP, SFTP, TELNET, LDAP, LDAPS, DICT, FILE, TFTP.

顺便说一句.不要将 SFTP 与 FTPS 混淆.SFTP 是 SSH 文件传输协议,而 FTPS 是 FTP over SSL.

BTW. SFTP is not to be confused with FTPS. SFTP is SSH File Transfer Protocol, while FTPS is FTP over SSL.

相关文章