Discussion:
Upload files to FTP Server
(too old to reply)
Susan
2006-01-13 11:11:17 UTC
Permalink
Is it possible to use vbscript to upload all files from a directory to a FTP
server?

Thanks in davance,

Susan
mr_unreliable
2006-01-13 21:34:18 UTC
Permalink
hi Susan,

afaik, there is no way in "pure" script to do this.

I suggest using an FTP utility, of which there are many.

http://www.google.com/search?hl=en&q=ftp+utility&btnG=Google+Search

Then you can just run the utility like any other app
(appactivate and sendkeys, and good luck to you!).

Personally, I use a copy of (free) WS_FTP95, which is no
longer available, but they have a newer verson -- called
WS_FTP (home) which is for sale at a very modest price.

Google turned up an FTP utility with an automation interface.
I haven't tried it, but an automation interface is way more
preferable to appactivate and sendkeys from a scripting
standpoint.

http://www.sofotex.com/Auto-FTP-Manager-download_L14419.html

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
Post by Susan
Is it possible to use vbscript to upload all files from a directory to a FTP
server?
Thanks in davance,
Susan
Susan
2006-01-14 11:55:22 UTC
Permalink
Found some examples susing windows FTP.exe.
Is it possible to use FTP.exe with VBScript without an imput file?
I'am new to VBScript, so i appreciate an example (with comments).

Regards,

Susan
y sakuda
2006-01-14 12:47:58 UTC
Permalink
Post by Susan
Found some examples susing windows FTP.exe.
Is it possible to use FTP.exe with VBScript without an imput file?
I'am new to VBScript, so i appreciate an example (with comments).
I suppose you must use input file.
Search Google with VBS and FTP. You can find many sample coding.
http://groups.google.com/groups?as_q=%EF%BD%86%EF%BD%94%EF%BD%90%E3%80%80vbs&num=10&scoring=r&hl=en&as_epq=&as_oq=&as_eq=&as_ugroup=&as_usubject=&as_uauthors=&lr=&as_drrb=q&as_qdr=&as_mind=1&as_minm=1&as_miny=1981&as_maxd=14&as_maxm=1&as_maxy=2006&safe=off

Y Sakuda from JPN
"Crash" Dummy
2006-01-14 14:16:31 UTC
Permalink
Post by Susan
Found some examples susing windows FTP.exe.
Is it possible to use FTP.exe with VBScript without an imput file?
I'am new to VBScript, so i appreciate an example (with comments).
Yes, but it makes the code much more tedious. The Windows FTP.exe program should
be your last choice for a scriptable client. If you have a regular GUI FTP
client, check to see if it has command line options. I use WS_FTP Pro, and it
has a robust set of command line instructions. With it, I could perform your
specific task in a single line of script. If you have another FTP client, search
the help file for "command line."

Another consideration is that ftp.exe will not operate in passive mode, which
may wreak havoc with your firewall.
--
Crash
deckhopper
2006-01-14 19:48:55 UTC
Permalink
This is how much scripting it takes to upload FTP files. You're
probably better off using a pre-built FTP client with command-lines.

My script below only stores username/password in a text file on the
desktop until the files are uploaded, then anything with a password in
it is deleted (permanently deleted) for privacy.

Try it out, see what you think (watch for wordwrap)

' ###################
' Start Script
' ###################
Option Explicit

Dim objShell, objShellApp, objNetwork, objFSO, objWMIService,
objRegistry
Dim strComputer, pswdFile, ftpTextFile, userDesktop, fullTextFilePath
Dim fullPswdFilePath, ftpCommand, strPassword, strUserId
Dim folderToUpload, ftpSite, ftpDir, fileTypesToUpload

strComputer="."

Set objShell = CreateObject("WScript.Shell")
Set objShellApp = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")


' No need to change this section
' ~~~~~~~~~~~~~~~~~~
pswdFile = "password.htm"
ftpTextFile = "ftpCommands.txt"
userDesktop = cStrDesktopPath
fullTextFilePath = buildMyFilePath(userDesktop,ftpTextFile)
fullPswdFilePath = buildMyFilePath(userDesktop,pswdFile)
ftpCommand = "ftp -i -s:"
' ~~~~~~~~~~~~~~~~~~


' Change this section to suit your own needs
' ~~~~~~~~~~~~~~~~~~
ftpSite = "ftp-www.earthlink.net"
ftpDir = "Flash"
fileTypesToUpload = "*.txt"
' ~~~~~~~~~~~~~~~~~~

folderToUpload = browseForFolder
createPswdFile(fullPswdFilePath)
runPswdHtml(fullPswdFilePath)
createFTPCommandsFile fullTextFilePath,ftpSite,strUserId,strPassword, _
ftpDir,folderToUpload, fileTypesToUpload

If (checkFileExists(fullTextFilePath)) Then
shellRun ftpCommand,fullTextFilePath
MsgBox "FTP Finished" & vbCr & vbCr _
& "Please confirm your files uploaded", 0, "Done"
deleteFiles(fullTextFilePath)
deleteFiles(fullPswdFilePath)
If Not (checkFileExists(fullTextFilePath)) _
And Not (checkFileExists(fullPswdFilePath)) Then
MsgBox "The above files have been deleted" _
& " for your privacy", _
0, quoteMe(pswdFile) & " & " & quoteMe(ftpTextFile)
End If
quitscript
Else
quitscript
End If



'******************************************************************************
Function shellRun(command,path)

Dim prompt

prompt = MsgBox(command & Chr(34) & path & Chr(34), 1, _
"Continue with command below?")

If prompt = 1 Then
objShell.Run command & Chr(34) & path & Chr(34), 1, True
Else
quitscript
End If

End Function
'*******************************************************************|


'******************************************************************************
Function cStrDesktopPath

cStrDesktopPath = CStr(LCase(objShell.SpecialFolders("Desktop")))

End Function
'*******************************************************************|


'******************************************************************************
Function quoteMe(x)

quoteMe = Chr(34) & x & Chr(34)

End Function
'*******************************************************************|


'******************************************************************************
Function browseForFolder

Dim objFolder, objFolder2
Dim ssfWINDOWS, ssfDRIVES, ssfPROFILE, ssfDESKTOP,
ssfDESKTOPDIRECTORY
Dim ssfPERSONAL

ssfWINDOWS = 36
ssfDRIVES = 17
ssfPROFILE = 40
ssfDESKTOP = 0
ssfDESKTOPDIRECTORY = 16
ssfPERSONAL = 5

Set objFolder = objShellApp.BrowseForFolder(0, _
"Choose Your Upload Folder", 0, ssfDESKTOP)

If (Not objFolder Is Nothing) Then
Set objFolder2 = objShellApp.NameSpace(objFolder)
If (Not objFolder2 Is Nothing) Then
Dim objFolderItem
Set objFolderItem = objFolder2.Self

If (Not objFolderItem Is Nothing) Then
Dim szReturn
szReturn = objFolderItem.Path
browseForFolder = szReturn
End If
End If
' MsgBox browseForFolder
Else
quitscript
End If

End Function
'*******************************************************************|


'******************************************************************************
Function createPswdFile(path)

Dim myFile

Set myFile = objFSO.CreateTextFile(path, True)
myFile.WriteLine("<HTML>")
myFile.WriteLine("<HEAD>")
myFile.WriteLine("<title>password.htm</title>")
myFile.WriteLine("<SCRIPT language=""VBScript"">")
myFile.WriteLine("<!--")
myFile.WriteLine("Function Window_OnLoad()")
myFile.WriteLine("UserID.focus()")
myFile.WriteLine("End Function")
myFile.WriteLine("Sub OKButton_OnClick")
myFile.WriteLine("OkClicked.Value = 1")
myFile.WriteLine("End Sub")
myFile.WriteLine("'-->")
myFile.WriteLine("</SCRIPT>")
myFile.WriteLine("</HEAD>")
myFile.WriteLine("<BODY>")
myFile.WriteLine("Your Username: <br><INPUT TYPE=text Name =
""UserID"" size=""50"">")
myFile.WriteLine("<p>")
myFile.WriteLine("Your Password: <br><INPUT TYPE=password Name =
""PasswordBox"" size=""20"">")
myFile.WriteLine("<p>")
myFile.WriteLine("<INPUT NAME=""OKButton"" TYPE=""BUTTON"" VALUE=""
OK "">")
myFile.WriteLine("<p>")
myFile.WriteLine("<input type=""hidden"" name=""OKClicked""
size=""20"" >")
myFile.WriteLine("</BODY>")
myFile.WriteLine("</HTML>")
myFile.WriteLine("<!--" &Now& " -->")
myFile.Close

End Function
'*******************************************************************|


'******************************************************************************
Function
createFTPCommandsFile(path,site,user,pswd,rmtDir,localDir,files)

Dim myFile

Set myFile = objFSO.CreateTextFile(path, True)
myFile.WriteLine("open")
myFile.WriteLine(site)
myFile.WriteLine(user)
myFile.WriteLine(pswd)
myFile.WriteLine("binary")
myFile.WriteLine("cd " & rmtDir)
myFile.WriteLine("lcd " & Chr(34) & localDir & Chr(34))
myFile.WriteLine("mput " & files)
myFile.WriteLine("bye")
myFile.Close

End Function
'*******************************************************************|


'******************************************************************************
Function checkFileExists(path)

checkFileExists = objFSO.FileExists(path)

' If Not (checkFileExists) Then
' MsgBox "Above file does not exist", 48, path
' Else
' MsgBox "Above File Exists, Continuing...", 0, path
' End If

End Function
'*******************************************************************|


'******************************************************************************
Function buildMyFilePath(folder,file)

buildMyFilePath = objFSO.BuildPath(folder, file)
' MsgBox buildMyFilePath, 0, "Result of 'buildMyFilePath' Function"

End Function
'*******************************************************************|


'******************************************************************************
Function deleteFiles(path)

If(checkFileExists(path)) Then
objFSO.DeleteFile(path)
Else
MsgBox "Above File Does Not Exist" _
& vbCr & vbCr & "Unable to Delete Above File" , 48, path
End If

End Function
'*******************************************************************|


'******************************************************************************
Function runPswdHtml(path)

On Error Resume Next

Dim objExplorer

Set objExplorer = WScript.CreateObject _
("InternetExplorer.Application", "IE_")

objExplorer.Navigate path
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 400
objExplorer.Height = 250
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1

Wscript.Sleep 1500

Do While (objExplorer.Document.All.OKClicked.Value = "")
errorHandler
If err.number <> 0 Then
MsgBox "Cancelled by User", 0, "Cancelled"
objExplorer.Quit
quitscript
End If
Wscript.Sleep 250
Loop

strPassword = objExplorer.Document.All.PasswordBox.Value
strUserID = objExplorer.Document.All.UserID.Value

objExplorer.Quit

End Function
'*******************************************************************|


'******************************************************************************
Function errorHandler

Dim genError

If err.Number <> 0 Then
If Err.Description = "" Then
genError = "General Error"
errorHandler = genError
End If
' MsgBox errorHandler, 0, "Error Code: " & err.number
End If

End Function
'*******************************************************************|


'******************************************************************************
Sub quitscript

MsgBox "Quitting Now"
Wscript.Quit

End Sub
'*******************************************************************|
' #################
' End Script
' #################
Susan
2006-01-14 19:57:51 UTC
Permalink
Looks great. I'll give it a try !!

Susan
Denton
2006-01-15 05:09:43 UTC
Permalink
Hi Susan:
there is a idea for your reference

in console mode "FTP -s" could accept commands from a text file and
the commands will automatically run

You could generate this file in VBS then use Shell Object to call FTP
command.



--
Post by Susan
Is it possible to use vbscript to upload all files from a directory to a FTP
server?
Thanks in davance,
Susan
Loading...