Topic "Upload files with archive bit set and then remove archive bi"

Author Message
schmidtc63

Guest


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
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
WinSCP can remove the archive attribute:
https://winscp.net/eng/docs/ui_transfer_custom

But it cannot select files with archive attribute for transfer.
_________________
Martin Prikryl
Guest




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

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.

Thanks,
Chris
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Please read
http://winscp.net/eng/docs/faq_script_ini
_________________
Martin Prikryl
Guest




prikryl wrote:


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 transfered, and if so, I turned the archive bit off.


Here's the code in .vbs format:


Code:
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 sucessfully transferred...
      fso.getfile(filename).attributes = fso.getfile(filename).attributes -32 'remove the archive attribute
   end if
next
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License