Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP of multiple files using 'mput' command

Status
Not open for further replies.

vgwprja

Programmer
Mar 27, 2008
24
0
0
US
I have a script that is supposed to ftp multiple files. I'm using the "mput" to do that. When I run the script it connects to the site but does not ftp the file. If I run the procedure manually (using DOS command screen) it works perfectly, I issue the "prompt off" and then the "mput" and all files are being ftp'ed. Could it be that I need to use some kind of "wait" between ecah ftp?. Here is the code:

'VBScript - FTP Outbound Files
Option Explicit
Dim objFSO, objMyFile, objShell, strFTPScriptFileName, strFilePut
Dim strLocalFolderName, strFTPServerName, strLoginID
Dim strPassword, strFTPServerFolder

'Set FTP options
strLocalFolderName = "e:\ftpdata\toclient\"
strFTPServerName = "ftp.client.com"
strLoginID = "myuserid"
strPassword = "mypassword"

'Set File name
strFilePut = "*.asc"
'strFilePut = "MyData_d03282008d151832.asc"

'Generate FTP command
strFTPScriptFileName = strLocalFolderName & "\FTPScript.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If (objFSO.FileExists(strFTPScriptFileName)) Then
objFSO.DeleteFile (strFTPScriptFileName)
End If

Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
objMyFile.WriteLine ("open " & strFTPServerName)
objMyFile.WriteLine (strLoginID)
objMyFile.WriteLine (strPassword)
objMyFile.WriteLine ("bin")
objMyFile.WriteLine ("lcd " & strLocalFolderName)
objMyFile.WriteLine ("prompt off")
objMyFile.WriteLine ("mput " & strFilePut)
objMyFile.WriteLine ("disconnect")
objMyFile.WriteLine ("bye")
objMyFile.Close

Set objFSO = Nothing
Set objMyFile = Nothing

'Execute the FTP script.
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run ("ftp -s:" & chr(34) & strFTPScriptFileName & chr(34))

Set objShell = Nothing
 
Replace this:
objMyFile.WriteLine (strLoginID)
objMyFile.WriteLine (strPassword)
with this:
objMyFile.WriteLine "user " & strLoginID & " " & strPassword

and this:
objShell.Run ("ftp -s:" & chr(34) & strFTPScriptFileName & chr(34))
with this:
objShell.Run "ftp -s:" & Chr(34) & strFTPScriptFileName & Chr(34), , True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Got the code finally working. The changes I did were:

1. from
"objMyFile.WriteLine "user " & strLoginID & " " & strPassword"
to
objMyFile.WriteLine (strLoginID)
objMyFile.WriteLine (strPassword)
it had to be in 2 separate lines, did not accept one line

2. also changed
strLocalFolderName = "e:\client\toreliance\"
that needed to be
"strLocalFolderName = "e:\client\toreliance"

'VBScript FTP Outbound Files to Reliance
Option Explicit
Dim objFSO, objMyFile, objShell, strFTPScriptFileName, strFilePut
Dim strLocalFolderName, strScriptFolder, strFTPServerName, strLoginID
Dim strPassword, strFTPServerFolder

'Set FTP options
strLocalFolderName = "e:\client\toreliance"
strFTPServerName = "ftp.client.com"
strLoginID = "muUserId"
strPassword = "myPassWord"

'Set File name
strFilePut = "*.asc"

'Generate FTP command
strFTPScriptFileName = strLocalFolderName & "FTP_Outbound_Files_to_Reliance.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If (objFSO.FileExists(strFTPScriptFileName)) Then
objFSO.DeleteFile (strFTPScriptFileName)
End If

Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
objMyFile.WriteLine ("open " & strFTPServerName)
objMyFile.WriteLine (strLoginID)
objMyFile.WriteLine (strPassword)
objMyFile.WriteLine ("bin")
objMyFile.WriteLine ("lcd " & strLocalFolderName)
objMyFile.WriteLine ("prompt off")
objMyFile.WriteLine ("mput " & strFilePut)
objMyFile.WriteLine ("disconnect")
objMyFile.WriteLine ("bye")
objMyFile.Close

'Execute the FTP script.
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run "ftp -s:" & Chr(34) & strFTPScriptFileName & Chr(34), , True

Set objFSO = Nothing
Set objMyFile = Nothing
Set objShell = Nothing

Thank you, thank you for helping me along....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top