簡體   English   中英

SSH2我在做什么錯?

[英]SSH2 what am I doing wrong?

我無法將文件從laravel項目復制到另一台服務器。 這就是我在做什么。

    $connection = ssh2_connect($this->ftpHostname, $this->ftpPort);

    if (!$connection) {
        throw new \Exception("Couldn't connect to {$this->ftpHostname}:{$this->ftpPort}");
    }

    $loginResult = ssh2_auth_password($connection, 'usrname', 'pswrd');

    if (!$loginResult) {
        throw new \Exception("Username or Password not accepted for {$this->ftpHostname}:{$this->ftpPort}");
    }

    $sftp = ssh2_sftp($connection);
    $fullFilePath = storage_path() .'/'.$this->argument('local-file');
    $remoteFilePath = "ssh2.sftp://{$sftp}/{$this->argument('remote-folder')}/SomeFolder/{$this->argument('remote-filename')}.txt";

    $copyResult = copy($fullFilePath, $remoteFilePath);

但這給了我這個錯誤

[ErrorException]
copy(): Unable to open ssh2.sftp://Resource id #621/My Folders/Upload only/sample.txt on remote host

我真的是ssh的新手,如何解決這個問題?

在ssh2.sftp:// fopen包裝器中使用$ sftp之前,將其轉換為int。

$remoteFilePath = "ssh2.sftp://" . (int)$sftp . "/{$this->argument('remote-folder')}/SomeFolder/{$this->argument('remote-filename')}.txt";

來自ssh2_sftp

除非將$ stftp強制轉換為(int)或使用intval(),否則上述示例代碼將失敗。

$ stream = fopen(“ ssh2.sftp:// $ sftp / path / to / file”,'r'); //失敗

$ stream = fopen(“ ssh2.sftp://”。(int)$ sftp。“ / path / to / file”,'r'); //歡樂

由於copy()將使用fopen包裝器來解釋ssh2.sftp:// uri,因此應該會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM