• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 62
  • Last Modified:

WinSCP script skipping files

I've made a script that will go out to a hosted FTP site and copy the files located there into a directory on my network. I close the session and then re-open it and move the files to an archive folder.

The issue I face is that from the time that the script is kicked off, until the time that it completes, new files could be added to this directory. When that does happen, they are not copied to my network location but are moved to the archive. Defeating the purpose of what the script is supposed to do.

In turn I need to do a treasure hunt to find the files that have been skipped.

What is the best way to handle that situation? Is there a way to temporary list the files somewhere that have been copied to the network then only move those when the second part of the script is engaged?

Here is the script:

# Make sure to have WinSCP downloaded first! 
# Set login name to diicorp 

# Automatically skips or ignores prompts 
option batch continue

# Allows for overwrites
option confirm off

# Opens session for diicorp
open diicorp

# Sets remote directory as root
cd /root

# Changes local working directory to X:\
lcd X:\

# Sets to ASCII
option transfer ascii 

# Gets multiple .txt files and copies to X:\
mget *.txt X:\

# Disconnects session
close

# Reopens session
open diicorp 

# Moves remote .txt files to /Archive folder  
mv *.txt /Archive/*.bak 

#Ends session
exit

Open in new window

0
CPKGDevTeam
Asked:
CPKGDevTeam
  • 2
  • 2
1 Solution
 
CFDSNSAMCommented:
You could do a FOR loop.  I don't have the exact context handy, but basically for each file it finds, copy it, archive it, then move onto the next.  That way the file is being archived immediately after it is copied and you don't have to worry about any modifications in between the copy and archive processes.  If a file is created while the script is running, it will not get copied, but also not get archived.
0
 
CPKGDevTeamAuthor Commented:
Thanks for the reply. I will look for examples of using LOOP in WinSCP - but I've only found the examples of lopping the script itself and not files within the script.

Any examples that you can supply would be most welcomed.

Thank you.
0
 
CFDSNSAMCommented:
Take a look at this post.  Sounds like the exact same thing you're doing.

Windows Task Scheduler running WinSCP Batch File
0
 
CPKGDevTeamAuthor Commented:
The author of that last article is attempting to do the same general process, but not using a loop within the script itself. His/her issue was more with the task scheduler not working. What I need is something that will work like this:

Open session to hosted ftp site
enter username/pw

For each rcv_*.txt file
Loop
Copy rcv_*.txt file using ASCII to network folder F:\netfolder
Move rcv_*txt file to ftp hosted site subfolder 'archive'
Next file

Until no more files in folder

close session

Any guidance there? I am trying to look into running it in something other than WinSCP

Thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now