我需要将本地文件FTP到Mainframe并编写以下脚本以使用streamwriter创建本地Batch文本文件,然后使用此文件和ftp -s:命令运行它。
这是代码。
Shared Sub TestFTP()
' BP DEFINED INPUTS ANDF OUTPUTS
'Inputs
Dim hostname As String
Dim username As String
Dim password As String
Dim mainfile As String
Dim localfile As String
'Outputs
Dim success As Boolean
Dim message As String
'-------------
'Test DATA
'-------------
hostname = "XXIBM2"
username = "USER1"
password = "XXX1234"
mainfile = "XXTSO.USER1.TEST2"
localfile = "D:\TestFTP.txt"
'=============================BP Code========================
Try
Dim localPath As String = "C:\BPFTP"
Dim isExists As Boolean = System.IO.Directory.Exists(localPath)
If (isExists = False) Then
System.IO.Directory.CreateDirectory(localPath)
End If
' Open StreamWriter And create batch file
Using writer As StreamWriter = New StreamWriter(localPath + "\\FTP.txt")
writer.WriteLine("open " + hostname)
writer.WriteLine(username)
writer.WriteLine(password)
writer.WriteLine("put " + localfile + " '" + mainfile + "'")
writer.WriteLine("bye")
writer.WriteLine("exit")
End Using
' Perform FTP
Interaction.Shell("ftp -n -s:C:\BPFTP\FTP.txt")
' Delete batch file
System.IO.File.Delete("C:\\BPFTP\\FTP.txt")
success = True
Catch e As Exception
success = False
message = e.Message
End Try
End Sub
如果我使用F5运行代码,则文件不会显示在主机上。
如果我在Shell命令中设置了一个breakpoing并将代码(f5)运行到此处,然后将F5运行到最后,则文件不会通过FTPd运行到大型机。
但是。
如果我将代码运行到断点,然后简单地“跳过”' Shell命令行使用F10,然后文件成功FTP到大型机。
答案 0 :(得分:3)
当您在调试模式下运行时,您正在强制执行同步操作,您需要告诉shell和您的ftp应用程序等待以完全发送文件。
Interaction.Shell("ftp -n -s:C:\BPFTP\FTP.txt", AppWinStyle.MinimizedFocus, True, 30000)
这会强制它在继续之前等待30秒,如果你将它设置为-1,它会永远等待,这会导致不良行为。