名称中带有空格的 mv 文件/文件夹不起作用 - LFTP

名称中带有空格的 mv 文件/文件夹不起作用 - LFTP

我有2个空间:
我的群晖NAS。和我的文件传输协议

如果我们假设本地 NAS 上的某些文件也在我的 FTP 存储库中,我想将本地 NAS 上和 FTP 上的一些文件移动到不同的文件夹中。

例如:从 FTP 下载文件到 NAS 后
网络存储:
-移动从 /volume1/Downloading/file001 到 /volume1/Downloaded/file001

FTP:
-移动从 /downloads/file001 到 /downloads/Finished/file001

NAS 上的每个文件都移动到正确的路径:好的
在我的 FTP 上,仅移动不包含空格的文件/文件夹:KO

这是我们需要了解的脚本的一部分:

#!/bin/sh
# Inits
ficLog=/volume1/ScriptsAndOutputs/logFTPSeedibox.txt
downloadingFolderPath=/volume1/Downloading
downloadedFolderPath=/volume1/Downloaded
ftpDestinationPath=FinishedTmp

# Configuration : ftp / user / pass
servFTP=server
userFTP=user
passFTP=password

for filePath in "${downloadingFolderPath}"/* ; do

    # As filePath is the complete path of the file we need to get the file NAME
    fileName=`basename "${filePath}"`
    #Try to move it on FTP
    lftp ftp://${userFTP}:${passFTP}@${servFTP} -e 'set ssl:verify-certificate false;set file:charset utf8;set ftp:charset utf8;cd downloads;mv "${fileName}" "${ftpDestinationPath}"'
    res2=$?

    #Then we move file on the NAS
    mv "${filePath}" "${downloadedFolderPath}"
done
exit 0

这是输出:

+ ficLog=/volume1/ScriptsAndOutputs/logFTPSeedibox.txt
+ downloadingFolderPath=/volume1/Downloading
+ downloadedFolderPath=/volume1/Downloaded
+ ftpDestinationPath=FinishedTmp
+ servFTP=server
+ userFTP=user
+ passFTP=password
+ for filePath in '"${downloadingFolderPath}"/*'
++ basename /volume1/Downloading/@eaDir
+ fileName=@eaDir
+ lftp ftp://user:password@server -e 'set ssl:verify-certificate false;set file:charset utf8;set ftp:charset utf8;cd downloads;mv "${fileName}" "${ftpDestinationPath}"'
cd ok, cwd=/downloads           
mv ${fileName}=>${ftpDestinationPath} [Waiting for response...]
mv: Access failed: 550 RNFR command failed. (${fileName})         
+ res2=1
+ mv /volume1/Downloading/@eaDir /volume1/Downloaded
mv: inter-device move failed: ‘/volume1/Downloading/@eaDir’ to ‘/volume1/Downloaded/@eaDir’; unable to remove target: Directory not empty
+ for filePath in '"${downloadingFolderPath}"/*'
++ basename '/volume1/Downloading/Folder With Files'
+ fileName='Folder With Files'
+ lftp ftp://user:password@server -e 'set ssl:verify-certificate false;set file:charset utf8;set ftp:charset utf8;cd downloads;mv "${fileName}" "${ftpDestinationPath}"'
cd ok, cwd=/downloads           
mv ${fileName}=>${ftpDestinationPath} [Waiting for response...]
mv: Access failed: 550 RNFR command failed. (${fileName})         
+ res2=1
+ mv '/volume1/Downloading/Folder With Files' /volume1/Downloaded
+ for filePath in '"${downloadingFolderPath}"/*'
++ basename /volume1/Downloading/Test_no_spaces.txt
+ fileName=Test_no_spaces.txt
+ lftp ftp://user:password@server -e 'set ssl:verify-certificate false;set file:charset utf8;set ftp:charset utf8;cd downloads;mv "${fileName}" "${ftpDestinationPath}"'
cd ok, cwd=/downloads           
mv ${fileName}=>${ftpDestinationPath} [Waiting for response...]
mv: Access failed: 550 RNFR command failed. (${fileName})         
+ res2=1
+ mv /volume1/Downloading/Test_no_spaces.txt /volume1/Downloaded
+ for filePath in '"${downloadingFolderPath}"/*'
++ basename '/volume1/Downloading/test_under et espaces.txt'
+ fileName='test_under et espaces.txt'
+ lftp ftp://user:password@server -e 'set ssl:verify-certificate false;set file:charset utf8;set ftp:charset utf8;cd downloads;mv "${fileName}" "${ftpDestinationPath}"'
cd ok, cwd=/downloads           
mv ${fileName}=>${ftpDestinationPath} [Waiting for response...]
mv: Access failed: 550 RNFR command failed. (${fileName})         
+ res2=1
+ mv '/volume1/Downloading/test_under et espaces.txt' /volume1/Downloaded
+ exit 0

正如您所看到的,它适用于 NAS 上的任何文件夹/文件,但仅适用于 FTP 上不带空格的文件/文件夹名称。

有人能帮我吗?谢谢。

答案1

这行:

lftp ftp://${userFTP}:${passFTP}@${servFTP} -e 'set ssl:verify-certificate false;set file:charset utf8;set ftp:charset utf8;cd downloads;mv "${fileName}" "${ftpDestinationPath}"'

-e位位于单引号中,这意味着 shell 不会用这些变量的值替换${fileName}或。${ftpDestinationPath}

要解决此问题,请使用双引号:

.... -e "set ssl:verify-certificate false;set file:charset utf8;set ftp:charset utf8;cd downloads;mv '${fileName}' '${ftpDestinationPath}'"

如果以某种方式失败(我当前无法测试它),请使用\"代替上面的每个单引号。

相关内容