简体   繁体   English

如何在 SFTP 存储中将目录从一个位置移动到另一个位置 laravel 9

[英]How I can Move directory from one location to another in SFTP storage laravel 9

Can anybody help me, I have to move files from one directory to another on SFTP storage.谁能帮我,我必须将文件从一个目录移动到 SFTP 存储上的另一个目录。

I have tried this我试过这个

$file = new Filesystem(); $file = 新文件系统(); $moved = $file->moveDirectory($from, $to); $moved = $file->moveDirectory($from, $to);

but for this I need full path to directory but with sftp following code is not working但是为此我需要目录的完整路径但是使用 sftp 以下代码不起作用

$full_path_source = Storage::disk('sftp')->getDriver()->getAdapter()->getPathPrefix('batch_1'); $full_path_source = Storage::disk('sftp')->getDriver()->getAdapter()->getPathPrefix('batch_1');

This is oddly very vague and surprisingly it cannot be found in Laravel Documentation nor API, but the Storage::move function is not only for files, but it will work on directories as well:奇怪的是,这非常模糊,令人惊讶的是,它在 Laravel 文档和 API 中都找不到,但是Storage::move function 不仅适用于文件,它也适用于目录:

Storage::move($oldDirectoryPath, $newDirectoryPath);

To get the path of your file, You can simply call:要获取文件的路径,您只需调用:

use Illuminate\Support\Facades\Storage;
 
$path = Storage::path('file.jpg');

File Paths : As found in the documentation: https://laravel.com/docs/9.x/filesystem#file-paths文件路径:如文档中所示: https://laravel.com/docs/9.x/filesystem#file-paths

You may use the path method to get the path for a given file.您可以使用 path 方法获取给定文件的路径。 If you are using the local driver, this will return the absolute path to the file.如果您使用的是本地驱动程序,这将返回文件的绝对路径。 If you are using the s3 driver, this method will return the relative path to the file in the S3 bucket:如果您使用的是 s3 驱动程序,此方法将返回 S3 存储桶中文件的相对路径:

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

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