ammartahir1978
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Steve
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
excellent
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\Administ
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