简体   繁体   English

phpseclib sftp->put() 命令:文件内容只是一个字符串,不是预期的 PDF 文档

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

I'm trying to upload a PDF document from a stage server to a remote location using $sftp-put();我正在尝试使用 $sftp-put() 将 PDF 文档从舞台服务器上传到远程位置;

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.我期待查看相同的 PDF,其中包含用户数据和一些用户上传的图像。 I've also confirmed that the original PDF has been created successfully on the staging server, it is intact and shows the relevant information.我还确认已在登台服务器上成功创建了原始 PDF,它完好无损并显示了相关信息。

The resulting file is created in the new remote server location however it is damaged/unreadable.生成的文件是在新的远程服务器位置创建的,但它已损坏/无法读取。

The output from var_dump($sftp->getSFTPLog()); 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!感觉我已经很好地遵循了 phpseclib 文档......尽管它是在屏幕前度过的漫长而漫长的日子之一!

Any advice greatly appreciated as always.任何建议一如既往地非常感谢。

You're using phpseclib 2.0.您正在使用 phpseclib 2.0。 I can tell because you're doing new SFTP() instead of new Net_SFTP() .我可以判断,因为您正在执行new SFTP()而不是new Net_SFTP() For 2.0 you need to do SFTP::SOURCE_LOCAL_FILE .对于 2.0,您需要执行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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM