How to find files and then PSFTP to local system?

1.1k Views Asked by At

I am trying to search for files in the Unix directrory and copy them to my local Windows machine using PSFTP.

I am running the below command:

sh = CreateObject("WScript.Shell")    
sh.Run "C:\PuTTY_Folder\PSFTP.EXE -b C:\PuTTY_Folder\script.txt user@host -pw password"

script.txt file:

lcd C:\Regression
cd /b2/batch/ABCD
find . -mtime 1 -name "*_000000022_*" -type f # I want to find the files and copy them to my local windows machine.
bye

find command isn't working with PSFTP. It says : unknown command find. I think I can use mget for copying multiple files, but not sure how to search and copy.

Please suggest.

Link to PSFTP documentation:

http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter6.html

1

There are 1 best solutions below

0
On

I was finally able to get this thing working.

    set sh = CreateObject("WScript.Shell")

    set fileExec = sh.Exec("C:\PuTTY_Folder\PLINK.EXE -pw password username@region find /filePickLoc/dir1 -name *batchID* -mmin -10 -type f") 

    filesStr = fileExec.StdOut.ReadAll

    filesStr = Left(filesStr, Len(filesStr) - 1)

    filesArray = Split(filesStr, vbLF)

    createScriptFile folderPath, arr, "filePickLoc/dir1"

    sh.Run "C:\PuTTY_Folder\PSFTP.EXE -b folderPath\Script.txt username@region -pw password", 7, True

    set fileExec = Nothing
    set sh = Nothing

With createScriptFile, i am creating a .txt file at runtime which is being used by PSFTP to transfer files.

Function createScriptFile(folderPath, files, loc)
    set oFSO = CreateObject("Scripting.FileSystemObject")
    set oFile = oFSO.CreateTextFile(folderPath & "\Script.txt", true)
    oFile.write "lcd " & folderPath & " " & vbCrLf
    oFile.write "cd /" & vbCrLf
    For Each x In files
        oFile.write "get " & x & " " & vbCrLf
    Next
    oFile.write "bye"
    oFile.Close
    set oFile = Nothing
    set oFSO = Nothing
End Function