如何查找文件并使用PSFTP将其传输到本地系统?

4

我正在尝试在Unix目录中搜索文件,并使用PSFTP将它们复制到我的本地Windows计算机。

我运行以下命令:

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

script.txt 文件:

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 命令在 PSFTP 中无法使用。显示:unknown command find. 我认为可以使用 mget 命令来复制多个文件,但不确定如何搜索和复制。请提供建议。
PSFTP 文档链接: http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter6.html

你不能在同一个脚本中混合使用 shell 和 FTP 命令(至少不是按照你混合它们的方式)。你需要在 plink 中运行 find 命令以获取要获取的文件列表,然后将其输入到 psftp 中。 - Ansgar Wiechers
@AnsgarWiechers:如果我使用plink,那么我是否需要在Unix中创建一个包含find结果的文件,然后通过FTP传输到我的本地机器?还是我可以直接将plink的输出通过|管道传送到PSFTP中? - Ejaz
@AnsgarWiechers:使用plink,我可以find到所需的文件,请建议是否可以直接将结果传递给PSFTP并获取它们。谢谢。 - Ejaz
1
我不这么认为。很可能你需要从plink输出中构建一个FTP脚本,并使用psftp运行生成的脚本。 - Ansgar Wiechers
1个回答

1

我终于成功让这个东西运行起来了。

    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

通过使用createScriptFile,我可以在运行时创建一个.txt文件,该文件被PSFTP用来传输文件。
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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接