move remote files with different extension

Advertisement

cipo80
Joined:
Posts:
4
Location:
Vicenza, Itay

move remote files with different extension

Hi All, I've build this simple script to get only .pdf from a remote SFTP, then move the pdf's and .xml to the remote directory "scaricati".
I've try with mv *.* /out/scaricati/*.* but isn't working, I've try splitting the two mv command and it's working.

Isn't important, but is it possible to move all files extension with one command?


Thanks in advance

open sftp://xxx:xxx@xxx:8022/ -hostkey="xxxxxxx="

cd /out

lcd "E:\report"

get *.pdf -filemask=/scaricati/

mv *.pdf /out/scaricati/*.pdf
mv *.xml /out/scaricati/*.xml

exit

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,469
Location:
Prague, Czechia

Re: move remote files with different extension

The mv *.* /out/scaricati/*.* should work in general.
The problem is probably the scaricati subfolder, as the the *.* matches even the subfolders. So the command is trying to move /out/scaricati to /out/scaricati/scaricati, what is obviously not possible. In such scenario, your solution is the best you can do.

Reply with quote

cipo80
Joined:
Posts:
4
Location:
Vicenza, Itay

Re: move remote files with different extension to a folder and create it if not exist.

martin wrote:

The mv *.* /out/scaricati/*.* should work in general.
The problem is probably the scaricati subfolder, as the the *.* matches even the subfolders. So the command is trying to move /out/scaricati to /out/scaricati/scaricati, what is obviously not possible. In such scenario, your solution is the best you can do.

Thank you Martin for the reply, I've another doubt, I'm not sure if the remote service delete the "scaricati" folder or not and I need it before moving files.
After some google-searches I've found an old post with the same scenario and I've added four commands rows before files moving.
I've understand the option batch continue if the directory already exist, and the mkdir, but I don't understand the last two commands option batch abort and stat foldername.

open sftp://xxx:xxx@xxx:8022/ -hostkey="xxxxxxx="
cd /out
lcd "E:\report"
get *.pdf -filemask=/scaricati/ 

option batch continue 
mkdir scaricati 
option batch abort 
stat scaricati

mv *.pdf /out/scaricati/*.pdf
mv *.xml /out/scaricati/*.xml

exit

Thanks in advance and have a great w.end!

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,469
Location:
Prague, Czechia

Re: move remote files with different extension to a folder and create it if not exist.

cipo80 wrote:

I've understand the option batch continue if the directory already exist, and the mkdir, but I don't understand the last two commands option batch abort and stat foldername.
With option batch continue the mkdir would succeed, even if it failed to create a (non-existent) directory. stat foldername (in abort mode) fails, if the folder/file does not exist. So it's a way to abort the script, if it failed to create the folder.
See also https://winscp.net/eng/docs/script_checking_file_existence#scripting

Reply with quote

Advertisement

You can post new topics in this forum