Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


martin wrote:


Here's the solution. All I wanted to do was traverse a directory and subdirectories, find files that had changed (via Windows's archive bit) but not been uploaded, upload those files and turn the archive bit off.

Using synchronize is out. It took winscp over an hour to simply compare the two directory structures, much less upload any files. Same with modify the .ini file, using a put command, only moving new or updated files and setting the archive bit. (if anyone is interested, the two .ini file settings are NewerOnly=1 and ClearArchive=1). This took way too long, too and was generally unreliable anyway.

So, here's what I did. I wrote a simple .vbs script that transversed the directory. Every time it found a file with the archive bit set (the file was new or changed), it queued that file in a winscp session. I then used the resulting .xml log file to figure out if the file was successfully transfered, and if so, I turned the archive bit off.

Here's the code in .vbs format:

set shell = WScript.CreateObject("WScript.Shell")

set exec = shell.Exec(" /log=c:\bin\transfer.xml")
' set up our session
exec.StdIn.Write("option batch continue" + vbCRLF & _
   "option batch continue" + vbCRLF & _
   "option confirm off" + vbCRLF & _
   "option transfer binary" + vbCRLF & _
   "option reconnecttime 300" + vbCRLF& _
   "open" + vbCRLF)

'set up a file system object that will traverse the directory we're checking
Set fso = CreateObject("Scripting.FileSystemObject")
set shell = WScript.CreateObject("WScript.Shell")

If WScript.Arguments.Unnamed.Count >= 1 Then
  If fso.FolderExists(WScript.Arguments.Unnamed(0)) Then
   strSourceDir = WScript.Arguments.Unnamed(0)
   strTargetDir = WScript.Arguments.Unnamed(1)
    Recurse fso.GetFolder(WScript.Arguments.Unnamed(0))
    WScript.Echo "Folder not found."
  End If
  WScript.Echo "Please give folder name as argument 1."
End If
Sub Recurse(f)
  For Each sf In f.SubFolders
    Recurse sf
   For Each sf In f.Files
      If sf.attributes and 32 Then 'archive attribute is set so lets upload that file
         exec.StdIn.Write("put """ + sf + """ """ + putfile + """" + vbCRLF)
         Wscript.Echo "put """ + sf + """ """ + putfile + """" + vbCRLF
      end if
End Sub
WScript.Echo "done looking..."
exec.StdIn.Write("exit" + vbCRLF) 'we've finished evaluating all the files. Our winscp session may still be going on, however...
sInput = exec.StdOut.ReadAll() 'this allows the session to complete. The script will pause here until it can "readall" the output

'lets look at the xml log file that winscp wrote
set doc = CreateObject("MSXML2.DOMDocument")
doc.async = false

' look for uploaded files
Set NodeList = doc.documentElement.selectNodes("//upload")

WScript.Echo("There are " & nodelist.length & " files")

'traverse all the uploaded files and look for those that were sucessfully uploaded so we can remove the archive bit
for i = 0 to NodeList.length - 1
    filename = nodelist(i).selectSingleNode("filename/@value").value
   if nodelist(i).selectSingleNode("result/@success").value="true" then 'if the file was sucessfully transferred...
      fso.getfile(filename).attributes = fso.getfile(filename).attributes -32 'remove the archive attribute
   end if

Re: Upload files with archive bit set and then remove archive bi

martin wrote:

WinSCP can remove the archive attribute:

But it cannot select files with archive attribute for transfer.

Ok but...
1. There is an option for "New and Updated files only" and then the option for removing the archive attribute.
2. If you'll read the question, I'm asking how to do those things in scripting, the topic of this forum.


Re: Upload files with archive bit set and then remove archive bi

WinSCP can remove the archive attribute:

But it cannot select files with archive attribute for transfer.

Upload files with archive bit set and then remove archive bi

In the GUI version of WinSCP, there is a setting that allows me to transfer files with the archive bit set and then remove the archive bit. How do I do this with an WinSCP script?

Synchronize is not an option because of the sheer size of the directories I'm scanning.