问题描述
我正在尝试使用$ sftp-put()将PDF文档从舞台服务器上载到远程位置;
I'm trying to upload a PDF document from a stage server to a remote location using $sftp-put();
代码:
$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());
我希望查看相同的PDF,其中包含用户数据和一些用户上传的图像.我还确认了原始PDF已在登台服务器上成功创建,它是完整的并显示了相关信息.
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.
var_dump($sftp->getSFTPLog());
的输出也不令人鼓舞:
The output from var_dump($sftp->getSFTPLog());
is not encouraging either:
bool(false)
我在这里做错了什么?感觉我已经很好地遵循了phpseclib文档...尽管它是屏幕前漫长而漫长的日子之一!
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.
推荐答案
您正在使用phpseclib 2.0.我知道是因为您正在执行new SFTP()
而不是new Net_SFTP()
.对于2.0,您需要执行SFTP::SOURCE_LOCAL_FILE
.例如.
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);
这篇关于phpseclib sftp-> put()命令:文件内容只是一个字符串,而不是预期的PDF文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!