名前にスペースが含まれる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ビットは一重引用符で囲まれています。これは、シェルが${fileName}これらの変数の値を置き換えないことを意味します。${ftpDestinationPath}

この問題を解決するには、二重引用符を使用します。

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

何らかの方法で失敗した場合(現在はテストできません)、上記の一\"重引用符を代わりに使用してください。

おすすめ記事