Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

winscp scrip for move and replace.

Posted on 2013-11-20
13
1,185 Views
Last Modified: 2013-12-18
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.bak'.
0
Comment
Question by:tristonyip
  • 7
  • 6
13 Comments
 
LVL 14

Expert Comment

by:sentner
ID: 39663169
Unfortunately, winscp is very limited in its basic command set.  There's no way to force the "mv" command to overwrite the files.  If you want to completely blow away all the backups each time you do this, you can first delete the files in /outgoing/completed.  Another option would be to create a separate folder for each day that you do this, and put the files there.

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
0
 

Author Comment

by:tristonyip
ID: 39663198
yes, the .net is more complex, can we add a timestamp on the txt file? and move to completed folder.

thanks
0
 
LVL 14

Expert Comment

by:sentner
ID: 39663727
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.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:tristonyip
ID: 39675725
that's two process, can i have one script to do the whole thing? or other program rather than Winscp ?
0
 
LVL 14

Expert Comment

by:sentner
ID: 39676012
Do you have direct command line access to the server in question?  If so, what OS is it?
0
 

Author Comment

by:tristonyip
ID: 39676020
yes, i can create and run cmd file. it's window 2003. thanks
0
 
LVL 14

Expert Comment

by:sentner
ID: 39676676
If you can run a cmd file, just do it with something like:

d:
cd outgoing
ren *.txt *.bak
move /y *.bak completed\
0
 

Author Comment

by:tristonyip
ID: 39678228
the reason we use winscp is for the sftp remote site. those outgoing and completed are in the remote site sftp server.
0
 
LVL 14

Expert Comment

by:sentner
ID: 39678302
Right, that's what I meant by "server".  Do you have direct command-line access to the remote server, via ssh for instance?
0
 

Author Comment

by:tristonyip
ID: 39678332
oh, no, we can not remote access the server.
0
 
LVL 14

Expert Comment

by:sentner
ID: 39678485
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

Open in new window

0
 

Author Comment

by:tristonyip
ID: 39690810
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
0
 
LVL 14

Accepted Solution

by:
sentner earned 500 total points
ID: 39690940
That'd only solve it for the first rename.  If you want to keep them in the same location, you can also rename them such as:

rm /outgoing/completed/*.bak3
mv /outgoing/completed/*.bak2 /outgoing/completed/*.bak3
mv /outgoing/completed/*.bak1 /outgoing/completed/*.bak2
mv /outgoing/completed/*.bak /outgoing/completed/*.bak1
mv *.txt  /outgoing/completed/*.bak
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need an overview of CSS pre-compilation 6 67
sumDigits  challenge 7 105
countHi challenge 25 140
algorithm 15 116
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question