none
vbscript to check which file uploaded successfully from multiple files RRS feed

  • Question

  • Hi Guys,

    My VBScript is uploading multiple files (by single command) successfully on different server. But can't keep a track of which file got uploaded successfully. 

    Now I want to implement a feature which will keep a track of files and will also check that which file from multiple files uploaded successfully. Please let me know how to implement this in my script.


    PT

    Saturday, November 22, 2014 4:09 PM

Answers

  • Ok.. I used PSFTP.. its showing status only after uploading all files. But I want a status of each and every file. Means once a single file from multiple file uploaded successfully, status in output file must be shown, then for 2nd file and so on.


    Same answer as before: Upload one file at a time, then check the output from PSFTP.exe. Note also that this is not really a scripting question. If PSFTP.exe reports its result only at the end of the run then there is nothing whatsoever that scripting can do about it.
    Saturday, November 22, 2014 5:40 PM

All replies

  • Please let me know how to implement this in my script.

    PT


    You need to post your script.
    Saturday, November 22, 2014 4:15 PM
  • Below is my script: 


    strHostname = "transfer.com"
    strUsername = "Test1"
    strPassword = "ABCD"
    strLocalDir = "C:\Demo"
    strRemoteDir = "/Data_files"
    strPSFTPexe = """c:\windows\ftp.exe"""
    strFtpScriptFile = "c:\myscript.txt"
    strOutputFile = "C:\output.txt"

    Set WshShell=CreateObject("Wscript.Shell")
    Set fso=CreateObject("Scripting.FileSystemObject")
    Set oFile=fso.OpenTextFile(strFtpScriptFile,2,true)

    oFile.WriteLine "lcd " & chr(34) & strLocalDir & chr(34)
    oFile.WriteLine "cd " & chr(34) & strRemoteDir & chr(34)
    oFile.WriteLine "ls" & chr(34)
    oFile.WriteLine "mput " & "*.DAT" & vbCrLf
    oFile.WriteLine "quit" & vbCrLf & vbCrLf
    oFile.Close
    Set WshShell= Nothing

    Set textFile = fso.OpenTextFile(strOutputFile,8,True)
    textFile.WriteLine "---------------------------File upload process started at [" & Now & "]-------------"
    textFile.Close

    strFTP = "%comspec% c:\windows\ftp.exe -n -s " & " -l " & strUsername & " -pw " & strPassword & " " & _
    strHostname & " -b " & strFtpScriptFile & "  >> " & strOutputFile & " 2>&1"

    Set Shell= CreateObject("Wscript.Shell")

    WshShell.Run strFTP,1,True
    WScript.Echo strTemp 

    Set textFile = fso.OpenTextFile(strOutputFile,8,True)

    If exec.Status = 0 Then : textFile.WriteLine "Files uploaded Successfully." : End If 

    'textFile.WriteLine ("Response:--   " + Result)
    'Set exec = Nothing
    Set fso= Nothing
    Set WshShell= Nothing

    WScript.Quit


    PT



    • Edited by Puneet Tiwari Saturday, November 22, 2014 4:39 PM comments removed
    Saturday, November 22, 2014 4:32 PM
  • After executing the Run methed, you must open your output file and examine it for success/failure of the FTP action.
    Saturday, November 22, 2014 5:07 PM
  • mput command uploads multiple files and put command upload single file. for single file we can check but when uploading multiple file unable to track which file is currently uploading and was uploaded successfully. Regarding output file, after checking everything I put a question on this forum.

    Could you please help me on how to implement a feature which will keep a track of files and will also check that which file from multiple files uploaded successfully.

     

    PT

    Saturday, November 22, 2014 5:15 PM
  • The native version of ftp.exe does not report file names when you use the mput command. Here are a few methods to get what you require:

    • Use some third-party version of ftp that is more flexible.
    • Upload one file at the time and check the ftp output individually for each file.
    • After uploading your files, use the ls command to find out what files exist on the remote machine. This might require a bit of coding.

    Saturday, November 22, 2014 5:29 PM
  • Ok.. I used PSFTP.. its showing status only after uploading all files. But I want a status of each and every file. Means once a single file from multiple file uploaded successfully, status in output file must be shown, then for 2nd file and so on. Please help

    strHostname = "transfer.com"
    strUsername = "Test1"
    strPassword = "ABCD"
    strLocalDir = "C:\Demo"
    strRemoteDir = "/Data_files"
    strPSFTPexe = """c:\windows\ftp.exe"""
    strFtpScriptFile = "c:\myscript.txt"
    strOutputFile = "C:\output.txt"

    Set WshShell=CreateObject("Wscript.Shell")
    Set fso=CreateObject("Scripting.FileSystemObject")
    Set oFile=fso.OpenTextFile(strFtpScriptFile,2,true)

    oFile.WriteLine "lcd " & chr(34) & strLocalDir & chr(34)
    oFile.WriteLine "cd " & chr(34) & strRemoteDir & chr(34)
    oFile.WriteLine "ls" & chr(34)
    oFile.WriteLine "mput " & "*.DAT" & vbCrLf
    oFile.WriteLine "quit" & vbCrLf & vbCrLf
    oFile.Close
    Set WshShell= Nothing

    Set textFile = fso.OpenTextFile(strOutputFile,8,True)
    textFile.WriteLine "---------------------------File upload process started at [" & Now & "]-------------"
    textFile.Close

    strPSFTP= "%comspec% c:\windows\PSFTP.exe -v -bc " & " -l " & strUsername & " -pw " & strPassword & " " & _
    strHostname & " -b " & strFtpScriptFile & "  >> " & strOutputFile & " 2>&1"

    Set Shell= CreateObject("Wscript.Shell")

    WshShell.Run strPSFTP,1,True


    Set textFile = fso.OpenTextFile(strOutputFile,8,True)


    If exec.Status = 0 Then : textFile.WriteLine "Files uploaded Successfully." : End If 

    Set exec = Nothing
    Set fso= Nothing
    Set WshShell= Nothing

    WScript.Quit


    PT

    Saturday, November 22, 2014 5:35 PM
  • Ok.. I used PSFTP.. its showing status only after uploading all files. But I want a status of each and every file. Means once a single file from multiple file uploaded successfully, status in output file must be shown, then for 2nd file and so on.


    Same answer as before: Upload one file at a time, then check the output from PSFTP.exe. Note also that this is not really a scripting question. If PSFTP.exe reports its result only at the end of the run then there is nothing whatsoever that scripting can do about it.
    Saturday, November 22, 2014 5:40 PM
  • PSFTP do not return any code. its just used to transfer file. tracking file upload is just like copying multiple files from one windows machine to another on network.

    If I say, that I want to transfer multiple files from one windows machine to another windows machine/server and want to track each and every file progress and upload status?


    PT


    • Edited by Puneet Tiwari Saturday, November 22, 2014 5:56 PM new word added
    Saturday, November 22, 2014 5:47 PM
  • If I want to transfer multiple files from one windows machine to another windows machine/server and want to track each and every file progress and upload status?

    Use ftp.exe in single file mode. Alternatively, use robocopy.exe.
    Saturday, November 22, 2014 6:18 PM
  • PSFTP do not return any code. its just used to transfer file. tracking file upload is just like copying multiple files from one windows machine to another on network.

    If I say, that I want to transfer multiple files from one windows machine to another windows machine/server and want to track each and every file progress and upload status?


    PT


    Puneet you have asked this same question many times. The answer will not change no matter how many times you ask it. FTP works the way it does. You cannot change that. Questions about PSFTP need to be asked of the developers of PSFTP. You can also hire a programmer to help you write a script that does what you want.


    ¯\_(ツ)_/¯


    • Edited by jrv Saturday, November 22, 2014 6:48 PM
    Saturday, November 22, 2014 6:45 PM
  • Looking up the stock FTP commands I see that debug can e turned on and it will echo filenames to log.

    To turn on debugging add "debug" to the command stream.


    ¯\_(ツ)_/¯

    Saturday, November 22, 2014 7:03 PM
  • Hi,

    I know that I asked many questions related to my script. Here I'm not asking about FTP or PSFTP but here what I'm asking is a concept and at this point what I would like to know is that.. Whenever we are copying or transferring multiple files at that time how to check that which file is getting copy or currently getting transfer thats it.



    PT


    Sunday, November 23, 2014 4:46 AM
  • You can't.  You can only check after the files are copied.


    ¯\_(ツ)_/¯

    Sunday, November 23, 2014 10:49 AM