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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript FTP Help

Status
Not open for further replies.

BTWright

Programmer
Mar 29, 2007
2
US
I need to write a script that has to ftp 4 different files from 1 server to an FTP site.
 
Here's what I got so far but It does not work. Please help

Option Explicit
Dim objFSO, objMyFile, objShell, strFTPScriptFileName, strFile2upload1, strFile2upload2, strFile2upload3, strFile2upload4
Dim strLocalFolderName1, strLocalFolderName2, strLocalFolderName3, strLocalFolderName4, strFTPServerName, strLoginID
Dim strPassword, strFTPServerFolder

'Customize code here to fit your needs
strLocalFolderName1 = "C:\test1"
strLocalFolderName2 = "C:\test2"
strLocalFolderName3 = "C:\test3"
strLocalFolderName4 = "C:\test4"

strFTPServerName = "ftp://spo-ftp-01.itron.com"
strLoginID = "*****"
strPassword = "****"
strFTPServerFolder = "Raw"

'The following code generates the file name on the FTP server you want to copy
strFile2upload1 = "test1"
strFile2upload2 = "test2"
strFile2upload3 = "test3"
strFile2upload4 = "test4"

'The follow lines of code generate the FTP script file on the fly,

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 ("cd " & strFTPServerFolder)
objMyFile.WriteLine ("ascii")
objMyFile.WriteLine ("lcd " & strLocalFolderName)
objMyFile.WriteLine ("copy" & strFile2upload1)
objMyFile.WriteLine ("bye")
objMyFile.Close
Set objFSO = Nothing
Set objMyFile = Nothing

'The following code executes the FTP script. It creates a Shell
'object and run FTP program on top of it.
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run ("ftp -s:" & chr(34) & strFTPScriptFileName & chr(34))
Set objShell = Nothing
 
Not sure if you got this working...

But here is what I see...
Change strLocalFolderName1 = "C:\test1"
To strLocalFolderName1 = "C:\test1\"


Change strFTPServerFolder = "Raw"
To strFTPServerFolder = "/Raw"

Change strFile2upload1 = "test1"
To strFile2upload1 = "test1.txt"

Copy is not an available command...
Change objMyFile.WriteLine ("copy" & strFile2upload1)
To objMyFile.WriteLine ("put" & strLocalFolderName1 & strFile2upload1 & " " & strFTPServerFolder)

You may need to include the filename with ftp folder
So instead you'd have:
strFTPServerFolder & "/" & strFile2upload1

If you open help in windows...
Type ftp... Hit enter

Then look at the available sub commands...

Hope this helps...




AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top