Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FTP

4 views
Skip to first unread message

Benny Pedersen

unread,
Feb 5, 2003, 7:51:44 PM2/5/03
to
Here's a litte FTP program that can fit on a floppy disk.
It is asking about a filename to upload.

If a profile exist on drive A, it will be used; else it will
ask about it.

What I would like to know is how I can let the output from the
ftp command remains open. I tried with C-Script instead but a
new window is opened and closed before I have the time to read it?
?

Benny Pedersen,

upLoad
sub Upload
' if (wScript.arguments.count) = 0 then
' createObject("wScript.shell").run "cScript.exe """ _
' & wScript.scriptFullName & """ //noLogo .",, false: exit sub
' elseIf (wScript.arguments(0)) = "." then
const forWriting= 2, forAppending= 8
dim wso: set wso= createObject("wScript.shell")
dim tmpPath: tmpPath= wso.expandEnvironmentStrings("%temp%")
dim fso: set fso= createObject("scripting.fileSystemObject")
dim tmpFile, favFile, proFile, f, host, user, pass
tmpFile= fso.getAbsolutePathName(tmpPath & ".\FTP.TMP")
favFile= fso.getAbsolutePathName(tmpPath & ".\fav.html")
proFile= "A:\PROFILE.TXT"
' else exit sub
' end if

if (fso.fileExists(proFile)) then
fso.copyFile proFile, tmpFile, true
msgBox "You may now remove your disk.", vbInformation, proFile
else host= inputBox("Host:",, "ftp.geocities.com")
user= inputBox("User:",, "VBS Freak")
pass= inputBox("Password:",, "*****")
set f= fso.openTextFile(tmpFile, forWriting, true)
f.writeLine "open " & host & vbCrLf & user & vbCrLf & pass
f.close
select case msgBox("Save this profile; """ & proFile & """"_
& vbCrLf & vbCrLf & "Open " _
& vbTab & "Host: " & vbTab & host & vbCrLf _
& vbTab & "User: " & vbTab & user & vbCrLf _
& vbTab & "Pass: " & vbTab & pass & vbCrLf _
& vbCrLf & "Press [Esc] to repeat your pr" _
& "ofile...", vbQuestion +vbYesNoCancel, "")
case vbCancel upLoad: exit sub
case vbYes fso.copyFile tmpFile, proFile, true
upLoad' [Repeat; use profile in drive A]
exit sub
end select
end if

'[Input a file name or press Enter:]
dim toUpFtp: toUpFtp= inputBox("Upload: ", "FTP", "Favorites")
toUpFtp= replace(toUpFtp, """", "")'[Allows quoted file input]

if (toUpFtp) = ("Favorites") then
dim uio: set uio= wScript.createObject("shell.uiHelper")
uio.importExportFavorites 0, favFile
set uio= nothing: toUpFtp= favFile
end if

if not (fso.fileExists(toUpFtp)) then
msgBox "File not found: " & toUpFtp, 16, "Error"
else
if vbYes=(wso.popup("Upload: """ & toUpFtp & """",, "FTP", _
vbQuestion +vbYesNo)) then
set f= fso.openTextFile(tmpFile, forAppending)
f.writeLine vbCrLf & "put """ & toUpFtp & """" _
& vbCrLf & "close" & vbCrLf & "quit"
f.close
wso.run "ftp -s:""" & tmpFile & """",, true
msgBox "Done: FTP command, put:" & vbCrLf & _
"""" & toUpFtp & """", 64, ";-)"
else
msgBox "Done: Not uploaded: """ & toUpFtp & """", 64, ";-)"
end if
wso.run "explorer " & fso.getParentFolderName(toUpFtp)
end if

fso.deleteFile tmpFile: set f= nothing: set fso= f: set wso= f
end sub

Tom Lavedas

unread,
Feb 6, 2003, 11:28:53 AM2/6/03
to
"Benny Pedersen" <b.ped...@get2net.dk> wrote in message news:<9mi0a.368$9m1...@news.get2net.dk>...

> Here's a litte FTP program that can fit on a floppy disk.
> It is asking about a filename to upload.
>
> If a profile exist on drive A, it will be used; else it will
> ask about it.
>
> What I would like to know is how I can let the output from the
> ftp command remains open. I tried with C-Script instead but a
> new window is opened and closed before I have the time to read it?
> ?
>
> Benny Pedersen,
>
> upLoad
> sub Upload

Change this line ...

> wso.run "ftp -s:""" & tmpFile & """",, true

To ...

wso.run "%comspec% /k ftp -s:""" & tmpFile & """",, true

> end sub

Tom Lavedas
===========

Benny Pedersen

unread,
Feb 6, 2003, 8:29:40 PM2/6/03
to

"Tom Lavedas" wrote news:b86eca15.03020...@posting.google.com...
> "Benny Pedersen" wrote in message news:<9mi0a.368$9m1...@news.get2net.dk>...

Hmmm, you probably do not belief that I considered
such a syntax (%comspec% /kFtp) but anyhow; if you
say so, then it can't be done better. Thanks, ;-).

*** Here's one that you would like:

Problem, [msgBox appears before closing a HTML page]:
set wso = createObject("wScript.shell")
wso.run "explorer " & filename.html, 3, true
msgBox "Hello"

After the Browser has opened filename.html, then
the MSGBOX appears immediately and before the HTML
is closed. Note: "wso.exec" can't solve that problem, ;-(.

Solution, [two loops]:
wso.run "explorer " & filename.html, 3, true
do until wso.appActivate("Titel"): wScript.sleep(99): loop
do while wso.appActivate("Titel"): wScript.sleep(99): loop
msgBox "Hello"

So therefore:
wso.run "explorer " & filename.html, 3, true
dim Z: Z= 100
do: wScript.sleep Z: if Z > 106 then exit do
Z= Z +1/9' [ if never activated, exit after 6 seconds ]
loop until wso.appActivate("Titel")
do while wso.appActivate("Titel"): wScript.sleep 99: loop
msgBox "Hello"

That's it.
***

' Benny Pedersen, http://2dos.homepage.dk
' (not uploaded),

'[FTP.VBS], (Tips: Replace string(8, " ") with "TAB" instead.)
upLoad
sub Upload


const forWriting= 2, forAppending= 8
dim wso: set wso= createObject("wScript.shell")
dim tmpPath: tmpPath= wso.expandEnvironmentStrings("%temp%")
dim fso: set fso= createObject("scripting.fileSystemObject")
dim tmpFile, favFile, proFile, f, host, user, pass
tmpFile= fso.getAbsolutePathName(tmpPath & ".\FTP.TMP")
favFile= fso.getAbsolutePathName(tmpPath & ".\fav.html")
proFile= "A:\PROFILE.TXT"

if (fso.fileExists(proFile)) then
fso.copyFile proFile,tmpFile,true
if (uCase(fso.GetDriveName(proFile))) = ("A:") _
then msgBox "You may now remove your disk.", 64, proFile
else host= inputBox("Host:", "", "ftp.geocities.com")
user= inputBox("User:", "", "VBS Freak")
pass= inputBox("Password:", "", "*****")


set f= fso.openTextFile(tmpFile, forWriting, true)
f.writeLine "open " & host & vbCrLf & user & vbCrLf & pass
f.close

select case msgBox("Save this profile; """ & proFile _
& """, " & vbCrLf & vbCrLf & "Open " _


& vbTab & "Host: " & vbTab & host & vbCrLf _
& vbTab & "User: " & vbTab & user & vbCrLf _
& vbTab & "Pass: " & vbTab & pass & vbCrLf _
& vbCrLf & "Press [Esc] to repeat your pr" _
& "ofile...", vbQuestion +vbYesNoCancel, "")
case vbCancel upLoad: exit sub
case vbYes fso.copyFile tmpFile, proFile, true

upLoad: exit sub
end select
end if

dim toUpFtp: toUpFtp= inputBox("Upload: ", "FTP", "Favorites")
toUpFtp= replace(toUpFtp, """", "")' [Allows quoted filename.]

if (toUpFtp) = ("Favorites") then
dim uio: set uio= wScript.createObject("shell.uiHelper")
uio.importExportFavorites 0, favFile
set uio= nothing: toUpFtp= favFile

wso.run "explorer " & toUpFtp, 3, -1
dim Z: Z= 100
do: wScript.sleep Z: if Z > 106 then exit do
Z= Z +1/9' [ if not activated, then exit after 6 seconds ]
loop until wso.appActivate("Bookmarks"): Z= 99
do while wso.appActivate("Bookmarks"): wScript.sleep Z: loop
end if

if not (fso.fileExists(toUpFtp)) then
msgBox "File not found: " & toUpFtp, 16, "Error"
else
if vbYes=(wso.popup("Upload: """ & toUpFtp & """",, "FTP",_
vbQuestion +vbYesNo)) then
set f= fso.openTextFile(tmpFile, forAppending)
f.writeLine vbCrLf & "put """ & toUpFtp & """" _
& vbCrLf & "close" & vbCrLf & "quit"
f.close

wso.run"%comSpec% /Kftp -s:""" & tmpFile & """", 3, true
end if
end if

' wso.run "explorer " & fso.getParentFolderName(toUpFtp)

Michael Harris (MVP)

unread,
Feb 6, 2003, 11:15:10 PM2/6/03
to
>
> Problem, [msgBox appears before closing a HTML page]:
> set wso = createObject("wScript.shell")
> wso.run "explorer " & filename.html, 3, true

Try:
wso.run filename.html, 3, true

> msgBox "Hello"
>


Your original code starts an explorer.exe (not iexplore.exe) process. The
explorer.exe start iexplore.exe and terminates while iexplore.exe continus
to run. Your script waits only for explore.exe to end, not the spawned
instance of iexplore.exe.


--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Windows 2000 Scripting Guide
Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp
Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp
Download details: System Administration Scripting Guide Scripts
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=B4CB2678-DAFB-4E30-B2DA-B8814FE2DA5A

Benny Pedersen

unread,
Feb 7, 2003, 6:10:33 AM2/7/03
to

Sounds logical (thanks), and it also works as you said.

Anyway; if an "explorer html" is followed by two loops,
the MSGBOX appears when the HTML page is closed without
a delay as "wso.run html" does. so I guess that the new
solution could still be useful anyway (as long that the
script don't exceed a multiply of 4096 bytes).


"Michael Harris (MVP)" wrote news:uKjgj9lzCHA.1632@TK2MSFTNGP12...

0 new messages