简体   繁体   中英

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();

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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