首页 > 解决方案 > 如何使用文件系统将文件从本地移动到 Laraver 中的 sftp 文件夹?

问题描述

我想使用 sftp 将文件从本地移动到另一台服务器,这是我在 config/filesystem.php 中的 sftp 设置

'sftp' => [
        'driver' => 'sftp',
        'host' => '192.xxx.0.xxx',
        'port' => 22,
        'username' => 'xxx',
        'password' => 'xxx',
        'root' => '/',
        'timeout' => 10,
    ],

这是我在控制器中的代码

 $file_local = public_path().'/documents/1.pdf';
 $file_sftp = Storage::disk('sftp')->put('1.pdf', $file_local);
 $move = File::move($file_local, $file_ftp);

我收到了这个错误 在此处输入图像描述

但在 sftp 文件夹中,文件存在但已损坏,请您帮忙 在此处输入图像描述

标签: phplaravelfilesystemssftpmove

解决方案


777许可!是邪恶的关键入口!我不会那样配置我的应用程序!我会先检查该文件是否仍然存在于存储文件夹中(您正在重命名的文件)。我的第二个假设 - 该文件由完全不同的用户拥有?通常整个项目应该在一个 user.group 所有者之下!在您的情况下可能是 apache.groupName 但您应该仔细检查。所以我会做

ls -la  // in project root directory and grab the ownerUser and ownerGroup names 
// then I ld make sure everything is owned by them - back up your project first before changing ownership!
sudo chown  -R ownerUser.ownerGroup *   // -R for recursive

如果没有,我会将其保存在存储文件夹以外的其他位置。希望这对你有帮助


推荐阅读