I need to FTP a local file to Mainframe and have written the below script to create a local Batch text file using streamwriter and then use this file with the ftp -s: command to run it.
Here is the code.
Shared Sub TestFTP()
' BP DEFINED INPUTS ANDF OUTPUTS
Dim hostname As String
Dim username As String
Dim password As String
Dim mainfile As String
Dim localfile As String
Dim success As Boolean
Dim message As String
hostname = "XXIBM2"
username = "USER1"
password = "XXX1234"
mainfile = "XXTSO.USER1.TEST2"
localfile = "D:\TestFTP.txt"
Dim localPath As String = "C:\BPFTP"
Dim isExists As Boolean = System.IO.Directory.Exists(localPath)
If (isExists = False) Then
' Open StreamWriter And create batch file
Using writer As StreamWriter = New StreamWriter(localPath + "\\FTP.txt")
writer.WriteLine("open " + hostname)
writer.WriteLine("put " + localfile + " '" + mainfile + "'")
' Perform FTP
Interaction.Shell("ftp -n -s:C:\BPFTP\FTP.txt")
' Delete batch file
success = True
Catch e As Exception
success = False
message = e.Message
When you run in debug mode, you are forcing a synchronous operation, you need to tell shell and your ftp application to wait in order to completely send the file.
Interaction.Shell("ftp -n -s:C:\BPFTP\FTP.txt", AppWinStyle.MinimizedFocus, True, 30000)
This will force it to wait 30 seconds before continuing, if you set it to -1 it waits forever which can cause undesirable behavior.