phpseclib rawlist() returns 错误

phpseclib rawlist() returns false

我最近使用 AWS Transfer 系列创建了一个 SFTP 站点。使用 FileZilla,我可以毫无问题地连接到站点、遍历目录、上传和下载文件。但是,当我使用 phpseclib SFTP 库时,我可以连接 username/password,但 rawlist()nlist() 返回 false。我仔细研究了 phpseclib 代码,发现真正的错误消息是 "Access deniedUS-ASCII"。我试图深入挖掘,但我对 SFTP/SSH 通信不够熟悉,无法理解我在看什么。任何有关这方面的信息将不胜感激。

这是 SFTP 日志的结果:

-> NET_SFTP_INIT (0.0001s)
00000000  00:00:00:03                                      ....

<- NET_SFTP_VERSION (1.8121s)
00000000  00:00:00:03                                      ....

-> NET_SFTP_REALPATH (0.0001s)
00000000  00:00:00:01:2e                                   .....

<- NET_SFTP_NAME (0.0518s)
00000000  00:00:00:01:00:00:00:11:2f:74:72:6b:2d:69:6e:73  ......../test-sf
00000010  69:67:68:74:2d:73:66:74:70:00:00:00:00:00:00:00  tp-bucket.......
00000020  00                                               .

-> NET_SFTP_OPENDIR (0.0001s)
00000000  00:00:00:10:2f:64:6f:63:75:6d:65:6e:74:73:2f:66  ..../documents/f
00000010  69:6c:65:73                                      iles

<- NET_SFTP_STATUS (0.2694s)
00000000  00:00:00:03:00:00:00:0d:41:63:63:65:73:73:20:64  ........Access d
00000010  65:6e:69:65:64:00:00:00:08:55:53:2d:41:53:43:49  enied....US-ASCI
00000020  49                                               I

FileZilla 日志:

2020-11-12 09:56:37 5158 1 Trace: We claim version: SSH-2.0-FileZilla_3.51.0
2020-11-12 09:56:38 5158 1 Trace: Remote version: SSH-2.0-AWS_SFTP_1.0
2020-11-12 09:56:38 5158 1 Trace: Using SSH protocol version 2
2020-11-12 09:56:38 5158 1 Trace: Doing ECDH key exchange with curve nistp256 and hash SHA-256 (unaccelerated)
2020-11-12 09:56:38 5158 1 Trace: Host key fingerprint is:
2020-11-12 09:56:38 5158 1 Trace: ssh-rsa 2048 a9:8d:e5:96:58:90:37:4b:42:60:24:66:ee:dd:72:a0 XKJp5iGNAQkwdbld69XapgzgIiiAgzji1T66HhhdRWU=
2020-11-12 09:56:38 5158 1 Trace: Initialised AES-256 GCM outbound encryption
2020-11-12 09:56:38 5158 1 Trace: Initialised AES256 GCM outbound MAC algorithm (in ETM mode) (required by cipher)
2020-11-12 09:56:38 5158 1 Trace: Initialised AES-256 GCM inbound encryption
2020-11-12 09:56:38 5158 1 Trace: Initialised AES256 GCM inbound MAC algorithm (in ETM mode) (required by cipher)
2020-11-12 09:56:38 5158 1 Trace: Pageant is running. Requesting keys.
2020-11-12 09:56:38 5158 1 Trace: Failed to get reply from Pageant
2020-11-12 09:56:38 5158 1 Status: Using username "blahlblahblah". 
2020-11-12 09:56:38 5158 1 Command: Pass: ******************
2020-11-12 09:56:38 5158 1 Trace: Sent password
2020-11-12 09:56:39 5158 1 Trace: Access granted
2020-11-12 09:56:39 5158 1 Trace: Opening main session channel
2020-11-12 09:56:39 5158 1 Trace: Opened main channel
2020-11-12 09:56:39 5158 1 Trace: Started a shell/command
2020-11-12 09:56:39 5158 1 Status: Connected to s-7d09f176684848268.server.transfer.us-east-2.amazonaws.com
2020-11-12 09:56:42 5158 1 Trace: Remote working directory is /test-sftp-bucket
2020-11-12 09:56:42 5158 1 Trace: CSftpConnectOpData::ParseResponse() in state 3
2020-11-12 09:56:42 5158 1 Trace: CControlSocket::ResetOperation(0)
2020-11-12 09:56:42 5158 1 Trace: CSftpConnectOpData::Reset(0) in state 3
2020-11-12 09:56:42 5158 1 Trace: CControlSocket::SendNextCommand()
2020-11-12 09:56:42 5158 1 Trace: CSftpListOpData::Send() in state 0
2020-11-12 09:56:42 5158 1 Status: Retrieving directory listing...
2020-11-12 09:56:42 5158 1 Trace: CSftpChangeDirOpData::Send() in state 0
2020-11-12 09:56:42 5158 1 Trace: CSftpChangeDirOpData::Send() in state 1
2020-11-12 09:56:42 5158 1 Command: pwd
2020-11-12 09:56:42 5158 1 Response: Current directory is: "/test-sftp-bucket"
2020-11-12 09:56:42 5158 1 Trace: CSftpChangeDirOpData::ParseResponse() in state 1
2020-11-12 09:56:42 5158 1 Trace: CControlSocket::ResetOperation(0)
2020-11-12 09:56:42 5158 1 Trace: CSftpChangeDirOpData::Reset(0) in state 1
2020-11-12 09:56:42 5158 1 Trace: CSftpListOpData::SubcommandResult(0) in state 1
2020-11-12 09:56:42 5158 1 Trace: CControlSocket::SendNextCommand()
2020-11-12 09:56:42 5158 1 Trace: CSftpListOpData::Send() in state 2
2020-11-12 09:56:42 5158 1 Trace: CSftpListOpData::Send() in state 3
2020-11-12 09:56:42 5158 1 Command: ls
2020-11-12 09:56:42 5158 1 Status: Listing directory /test-sftp-bucket
2020-11-12 09:56:42 5158 1 Trace: CSftpListOpData::ParseResponse() in state 3
2020-11-12 09:56:42 5158 1 Trace: CControlSocket::ResetOperation(0)
2020-11-12 09:56:42 5158 1 Trace: CSftpListOpData::Reset(0) in state 3
2020-11-12 09:56:42 5158 1 Status: Directory listing of "/test-sftp-bucket" successful
2020-11-12 09:56:51 5158 1 Trace: CControlSocket::SendNextCommand()
2020-11-12 09:56:51 5158 1 Trace: CSftpListOpData::Send() in state 0
2020-11-12 09:56:51 5158 1 Status: Retrieving directory listing of "/test-sftp-bucket/documents"...
2020-11-12 09:56:51 5158 1 Trace: CSftpChangeDirOpData::Send() in state 0
2020-11-12 09:56:51 5158 1 Trace: CSftpChangeDirOpData::Send() in state 2
2020-11-12 09:56:51 5158 1 Command: cd "/test-sftp-bucket/documents"
2020-11-12 09:56:51 5158 1 Response: New directory is: "/test-sftp-bucket/documents"
2020-11-12 09:56:51 5158 1 Trace: CSftpChangeDirOpData::ParseResponse() in state 2
2020-11-12 09:56:51 5158 1 Trace: CControlSocket::ResetOperation(0)
2020-11-12 09:56:51 5158 1 Trace: CSftpChangeDirOpData::Reset(0) in state 2
2020-11-12 09:56:51 5158 1 Trace: CSftpListOpData::SubcommandResult(0) in state 1
2020-11-12 09:56:51 5158 1 Trace: CControlSocket::SendNextCommand()
2020-11-12 09:56:51 5158 1 Trace: CSftpListOpData::Send() in state 2
2020-11-12 09:56:51 5158 1 Trace: CSftpListOpData::Send() in state 3
2020-11-12 09:56:51 5158 1 Command: ls
2020-11-12 09:56:51 5158 1 Status: Listing directory /test-sftp-bucket/documents
2020-11-12 09:56:52 5158 1 Trace: CSftpListOpData::ParseResponse() in state 3
2020-11-12 09:56:52 5158 1 Trace: CControlSocket::ResetOperation(0)
2020-11-12 09:56:52 5158 1 Trace: CSftpListOpData::Reset(0) in state 3
2020-11-12 09:56:52 5158 1 Status: Directory listing of "/test-sftp-bucket/documents" successful
2020-11-12 09:56:53 5158 1 Trace: CControlSocket::SendNextCommand()
2020-11-12 09:56:53 5158 1 Trace: CSftpListOpData::Send() in state 0
2020-11-12 09:56:53 5158 1 Status: Retrieving directory listing of "/test-sftp-bucket/documents/files"...
2020-11-12 09:56:53 5158 1 Trace: CSftpChangeDirOpData::Send() in state 0
2020-11-12 09:56:53 5158 1 Trace: CSftpChangeDirOpData::Send() in state 2
2020-11-12 09:56:53 5158 1 Command: cd "/test-sftp-bucket/documents/files"
2020-11-12 09:56:53 5158 1 Response: New directory is: "/test-sftp-bucket/documents/files"
2020-11-12 09:56:53 5158 1 Trace: CSftpChangeDirOpData::ParseResponse() in state 2
2020-11-12 09:56:53 5158 1 Trace: CControlSocket::ResetOperation(0)
2020-11-12 09:56:53 5158 1 Trace: CSftpChangeDirOpData::Reset(0) in state 2
2020-11-12 09:56:53 5158 1 Trace: CSftpListOpData::SubcommandResult(0) in state 1
2020-11-12 09:56:53 5158 1 Trace: CControlSocket::SendNextCommand()
2020-11-12 09:56:53 5158 1 Trace: CSftpListOpData::Send() in state 2
2020-11-12 09:56:53 5158 1 Trace: CSftpListOpData::Send() in state 3
2020-11-12 09:56:53 5158 1 Command: ls
2020-11-12 09:56:53 5158 1 Status: Listing directory /test-sftp-bucket/documents/files
2020-11-12 09:56:53 5158 1 Trace: CSftpListOpData::ParseResponse() in state 3
2020-11-12 09:56:53 5158 1 Trace: CControlSocket::ResetOperation(0)
2020-11-12 09:56:53 5158 1 Trace: CSftpListOpData::Reset(0) in state 3
2020-11-12 09:56:53 5158 1 Status: Directory listing of "/test-sftp-bucket/documents/files" successful

您使用的路径错误。

使用 GUI SFTP 客户端登录并检查那里的路径。然后在您的 PHP 代码中使用相同的完整路径。