Link to home
Start Free TrialLog in
Avatar of ammartahir1978
ammartahir1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

how to read a text file through VBS

Hi All i have a script which is uploading a single file on to ftp, but i want to put multiple files on to ftp.

how can i read the text file in which i can add item which i need to upload to ftp server?

i have attach  script which i am using

thank for your help
strFTPServer = "IPADDRESS"
strUsername = "USERNAME"
strPassword = "PASSWORD"
strFileToUpload = "C:\Users\Administrator\Desktop"
Set objNetwork = CreateObject("WScript.Network")
strFolderToCreate = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & "_" & objNetwork.ComputerName

Set objFSO = CreateObject("Scripting.FileSystemObject")
strFileToUpload = objFSO.GetFile(strFileToUpload).ShortPath
strFTPScript = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "FTPCommands.txt"
Set objFTP = objFSO.CreateTextFile(strFTPScript, True)
objFTP.WriteLine "open " & strFTPServer
objFTP.WriteLine strUsername
objFTP.WriteLine strPassword
objFTP.WriteLine "cd DIRECTORY"
objFTP.WriteLine "mkdir " & strFolderToCreate
objFTP.WriteLine "cd " & strFolderToCreate
objFTP.WriteLine "put " & strFileToUpload
objFTP.WriteLine "bye"
objFTP.Close
strFTPScript = objFSO.GetFile(strFTPScript).ShortPath

Set objShell = CreateObject("WScript.Shell")
objShell.Run "cmd /k ftp -s:" & strFTPScript, 1, True

objFSO.DeleteFile strFTPScript, True

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rushtoshankar
rushtoshankar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steve Knight
Or even use the batch script version I gave you in your last Q:

Have added "prompt" command to stop it asking overwrite if needed too.

This new line just say to run down the lines in the file shown and add the line "put filename" for each:
for /f "delims=" %%a in ('Type %filelist%') do echo put %%a

@echo off
set FTPServer=IPADDRESS
set Username=USERNAME
set Password=PASSWORD
set LocalDir=C:\Users\Administrator\Desktop
set RemoteDir=street/Windows
set FileList="filelist.txt"

REM Get date in form yyyymmdd_computername
echo wscript.echo Year(Date) ^& Right("0" ^& Month(Date), 2) ^& Right("0" ^& Day(Date), 2) ^& "_%computername%" > "%temp%\getdate.vbs
for /f "tokens=*" %%a in ('cscript //nologo "%temp%\getdate.vbs"') do set yyyymmdd=%%a

(echo open %FTPServer%
echo user %UserName%
echo %Password%
echo prompt
echo lcd %LocalDir%
echo cd %RemoteDir%
md %yyyymmdd%
cd %yyyymmdd%
for /f "delims=" %%a in ('Type %filelist%') do echo put %%a
echo quit
) | ftp -n -i
 

Steve
It just seems silly to me like I say running a VBScript to make a text file to call ftp.exe rather than just doing it all with one ftp command in batch file?

Steve
Avatar of ammartahir1978

ASKER

hi Dragon-it,

how can i your script run?

can you please give step by step instructions?

Thank you so much

thank you for your reply rushtoshankar i can see you added listoffile.txt in the vbs, so can i just put different files in that txt file on each line and also the files which are on differnet location then current computer?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
excellent