You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

远程同目录下将文件从源文件夹移至归档文件夹失败求助

解决psftp执行mv命令移动文件失败的问题

可能的原因及对应解决方案

1. 目标目录不存在或路径错误

  • 先验证目标目录是否存在,在命令列表中添加ls /specific/directory/path/destination,确认能正常列出目录内容
  • 核对错误信息中的路径:错误返回的路径是/user/specific/...,你代码里写的是/specific/...,可能实际路径需要加上/user/前缀,修正mv命令的路径为/user/specific/directory/path/source/* /user/specific/directory/path/destination

2. psftp的mv命令不支持通配符

部分SFTP客户端的mv命令不支持*通配符批量移动文件,可尝试两种解决方式:

  • 改用SSH执行远程shell命令(如果服务器允许SSH连接):
    $sshPath = "local/path/to/ssh.exe"
    & $sshPath -pw $password "$User@$Host" "mv /user/specific/directory/path/source/* /user/specific/directory/path/destination"
    
  • 通过psftp逐个移动文件:先获取源目录文件列表,再循环执行mv命令
    $psftpPath = "local/path/to/psftp.exe"
    # 获取源目录文件列表(过滤出文件名)
    $fileList = & $psftpPath -pw $password "$User@$Host" -be "ls /user/specific/directory/path/source" | ForEach-Object {
        if ($_ -match '^\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+\.\S+)$') { $matches[1] }
    }
    # 逐个移动文件
    foreach ($file in $fileList) {
        $mvCmd = "mv /user/specific/directory/path/source/$file /user/specific/directory/path/destination/$file"
        & $psftpPath -pw $password "$User@$Host" -be $mvCmd
    }
    

3. 权限不足

  • 手动登录psftp,执行ls -l /user/specific/directory/path/source查看源文件的权限,确认当前用户有读取/修改权限
  • 执行ls -ld /user/specific/directory/path/destination查看目标目录权限,确认当前用户有写入权限
  • 如果权限不足,联系服务器管理员调整权限

4. 目标目录路径末尾需加斜杠

尝试在目标目录路径末尾添加/,修正mv命令为:

mv /user/specific/directory/path/source/* /user/specific/directory/path/destination/

内容的提问来源于stack exchange,提问作者undetected

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 03:00:56