tristonyip
asked on
winscp scrip for move and replace.
hi
i try to use winscp scrip to remove a and rename a file on the remote site. but i got a problem by using MV , one the .bak file exist on the folder. is it away to replace the existing file in winscp scrip?
mv *.txt /outgoing/completed/*.bak
Error moving file 'test_20131101.txt' to '/outgoing/completed/test_ 20131101.b ak'.
i try to use winscp scrip to remove a and rename a file on the remote site. but i got a problem by using MV , one the .bak file exist on the folder. is it away to replace the existing file in winscp scrip?
mv *.txt /outgoing/completed/*.bak
Error moving file 'test_20131101.txt' to '/outgoing/completed/test_
ASKER
yes, the .net is more complex, can we add a timestamp on the txt file? and move to completed folder.
thanks
thanks
Yes, you could add a timestamp as well, but not with the basic winscp commands. It'd have to be done outside that process, in the script that calls winscp.
ASKER
that's two process, can i have one script to do the whole thing? or other program rather than Winscp ?
Do you have direct command line access to the server in question? If so, what OS is it?
ASKER
yes, i can create and run cmd file. it's window 2003. thanks
If you can run a cmd file, just do it with something like:
d:
cd outgoing
ren *.txt *.bak
move /y *.bak completed\
d:
cd outgoing
ren *.txt *.bak
move /y *.bak completed\
ASKER
the reason we use winscp is for the sftp remote site. those outgoing and completed are in the remote site sftp server.
Right, that's what I meant by "server". Do you have direct command-line access to the remote server, via ssh for instance?
ASKER
oh, no, we can not remote access the server.
How many of the "completed" files do you want to keep? You could always do a simple round-robin mv, deleting the oldest ones, and successively moving into different directories, like this:
rm /outgoing/completed3/*.bak
mv /outgoing/completed2/*.bak /outgoing/completed3
mv /outgoing/completed1/*.bak /outgoing/completed2
mv /outgoing/completed/*.bak /outgoing/completed1
mv *.txt /outgoing/completed/*.bak
ASKER
well, we would like to keep them in one location. i find the way to solved my issue, if there is an error on the .bak, i will move the rest of files in .txt to avoid the name issue. thanks
mv *.txt /outgoing/completed/*.bak
mv *.txt /outgoing/completed/*.txt
mv *.txt /outgoing/completed/*.bak
mv *.txt /outgoing/completed/*.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Finally, you could use a more robust script, to first check each individual file in the base directory, check the completed directory for existence of a backup (and remove if it exists), and then do the move.
You can also do this using .NET wrapper, though it's much more complex:
http://winscp.net/eng/docs/library