I have 2 spaces:
My Synology NAS. And my FTP.
If we assume that some files on my local NAS are also in my FTP repository, I want to move some files on my local NAS AND on my FTP on different folders.
eg: After downloading files from FTP to NAS
NAS:
- Move from /volume1/Downloading/file001 to /volume1/Downloaded/file001
FTP:
- Move from /downloads/file001 to /downloads/Finished/file001
Every files on the NAS are moved at the right path : OK
On my FTP, only files/folders that doesn't contain blank spaces are moved : KO
So here is a part of the script we need to know:
#!/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
Here is the output :
+ 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
As you can see, it's working for any folder/file on the NAS but only for files/folders names without blank-spaces on the FTP.
Can someone help me? Thanks.