Solved

FTP, AS/400 and VB

Posted on 2004-03-30
7
640 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:viselli
  • 5
7 Comments
 
LVL 7

Expert Comment

by:ramesh12
ID: 10716677
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)
0
 
LVL 7

Expert Comment

by:ramesh12
ID: 10716786
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)
0
 
LVL 7

Expert Comment

by:ramesh12
ID: 10716787
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)
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 7

Expert Comment

by:ramesh12
ID: 10716798
Sorry for the double post.
0
 

Author Comment

by:viselli
ID: 10716857
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.
0
 
LVL 5

Expert Comment

by:g0rath
ID: 10716873
0
 
LVL 7

Accepted Solution

by:
ramesh12 earned 125 total points
ID: 10716932
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question