Link to home
Start Free TrialLog in
Avatar of viselli
viselli

asked on

FTP, AS/400 and VB

Does anyone have simple sample code in VB that will allow me to download a file from the AS/400 using FTP.
The file name on the AS/400 is known and will not change and also the file name on the PC will not change as well. It's just a strait copy without any user intervention.

Can someone please help me.

Thanks.
Avatar of ramesh12
ramesh12

Use something like this


Dim WshShell, curDir, wShell, file

Set wShell = WScript.CreateObject("Shell.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.OpenTextFile("sometextfile.txt",2,True)

file = InputBox ("Which file will you upload?","File adder")

OutPutFile.WriteLine "open [ftp server]" 'Connects to the ftp server
OutPutFile.WriteLine "[username]"
OutPutFile.WriteLine "[password]"
OutPutFile.WriteLine "Lcd [folder]"
OutPutFile.WriteLine "Get " & file 'Adds the file to the ftp server
OutPutFile.WriteLine "bye" 'Quit.
OutPutFile.Close



Set wShell = Nothing
Set WshShell = Nothing
Set FileSystem = Nothing
Set OutPutFile = Nothing
WScript.Quit(0)
Oops sorry

Here is the code again

Dim WshShell, curDir, wShell, file

Set wShell = WScript.CreateObject("Shell.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.OpenTextFile("sometextfile.txt",2,True)

file = InputBox ("Which file will you upload?","File adder")

OutPutFile.WriteLine "open [ftp server]" 'Connects to the ftp server
OutPutFile.WriteLine "[username]"
OutPutFile.WriteLine "[password]"
OutPutFile.WriteLine "cd [folder]"
OutPutFile.WriteLine "put " & file 'Adds the file to the ftp server
OutPutFile.WriteLine "bye" 'Quit.
OutPutFile.Close

curDir = WshShell.CurrentDirectory
wShell.Open curDir & "\batfile.bat"

Set wShell = Nothing
Set WshShell = Nothing
Set FileSystem = Nothing
Set OutPutFile = Nothing
WScript.Quit(0)
Oops sorry

Here is the code again

Dim WshShell, curDir, wShell, file

Set wShell = WScript.CreateObject("Shell.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.OpenTextFile("sometextfile.txt",2,True)

file = InputBox ("Which file will you upload?","File adder")

OutPutFile.WriteLine "open [ftp server]" 'Connects to the ftp server
OutPutFile.WriteLine "[username]"
OutPutFile.WriteLine "[password]"
OutPutFile.WriteLine "cd [folder]"
OutPutFile.WriteLine "put " & file 'Adds the file to the ftp server
OutPutFile.WriteLine "bye" 'Quit.
OutPutFile.Close

curDir = WshShell.CurrentDirectory
wShell.Open curDir & "\batfile.bat"

Set wShell = Nothing
Set WshShell = Nothing
Set FileSystem = Nothing
Set OutPutFile = Nothing
WScript.Quit(0)
Sorry for the double post.
Avatar of viselli

ASKER

Thanks for your prompt response.

When I try this I get the message "Expected variable or procedure, not module" on the line that read "Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")"

Unsure what to do this this?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of ramesh12
ramesh12

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