phpseclib sftp->put() command: File contents are just a string, not the expected PDF document

与世无争的帅哥 提交于 2020-04-11 08:23:09

问题


I'm trying to upload a PDF document from a stage server to a remote location using $sftp-put();

CODE:

$sftp = new SFTP($config::SFTP_SERVER);

// login to remote server
if (!$sftp->login($config::SFTP_USER, $config::SFTP_PASSWORD)) {
    throw new Exception('Login failed');
}

// move to relevant directory
$sftp->chdir('fatca');

// upload file
$uploadFile = $sftp->put('test-pdf-upload.pdf', '/srv/www/vhosts/stage.johno.com/fatca/src/uploads/pdfs/345-553453-434__05122017_16:45:26.pdf', NET_SFTP_LOCAL_FILE);

// Error checking for local env only
var_dump($uploadFile);
var_dump($sftp->getSFTPLog());

I'm expecting to view the same PDF, that contains user data and some user uploaded images. I've also confirmed that the original PDF has been created successfully on the staging server, it is intact and shows the relevant information.

The resulting file is created in the new remote server location however it is damaged/unreadable.

The output from var_dump($sftp->getSFTPLog()); is not encouraging either:

bool(false)

What am I doing wrong here? Feel like I've followed the phpseclib documentation well... Although its been one of those long, long days in front of the screen!

Any advice greatly appreciated as always.


回答1:


You're using phpseclib 2.0. I can tell because you're doing new SFTP() instead of new Net_SFTP(). For 2.0 you need to do SFTP::SOURCE_LOCAL_FILE. eg.

$uploadFile =
    $sftp->put(
      'test-pdf-upload.pdf',
      '/srv/www/vhosts/stage.johno.com/fatca/src/uploads/pdfs/345-553453-434__05122017_16:45:26.pdf',
      SFTP::SOURCE_LOCAL_FILE);


来源:https://stackoverflow.com/questions/47659231/phpseclib-sftp-put-command-file-contents-are-just-a-string-not-the-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!