Post a reply

Options
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)

Options

Topic review

Mixter

Great post!

@Guest: Great post! Thank you! I had to do a few of my own tweaks, but this was exactly what I needed.
Guest

OK....

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 transferred, 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("winscp.com /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 myuser@myserver.xxx" + 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))
  Else
    WScript.Echo "Folder not found."
  End If
Else
  WScript.Echo "Please give folder name as argument 1."
End If
 
 
Sub Recurse(f)
  For Each sf In f.SubFolders
    Recurse sf
  Next
 
  For Each sf In f.Files
    If sf.attributes And 32 Then 'archive attribute is set so lets upload that file
      putfile = replace(sf, strSourceDir, strTargetDir, 1, -1, 1)
      putfile = replace(putfile, "\", "/")
      exec.StdIn.Write("put """ + sf + """ """ + putfile + """" + vbCRLF)
      Wscript.Echo "put """ + sf + """ """ + putfile + """" + vbCRLF
    End If
  Next
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
doc.load("c:\bin\transfer.xml")
 
' 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 successfully transferred...
    fso.getfile(filename).attributes = fso.getfile(filename).attributes -32 'remove the archive attribute
  End If
Next
Guest

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

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.

Thanks, Chris
martin

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

WinSCP can remove the archive attribute:
https://winscp.net/eng/docs/ui_transfer_custom

But it cannot select files with archive attribute for transfer.
schmidtc63

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.

Thanks,
Chris