【发布时间】:2016-11-23 21:56:33
【问题描述】:
我需要将本地文件通过 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 命令处设置断点并将代码 (f5) 运行到此处,然后 F5 到末尾,则文件不会通过 FTP 传输到大型机。
但是。
如果我将代码运行到断点,然后使用 F10 简单地“跳过”Shell 命令行,则文件成功地通过 FTP 传输到大型机。
【问题讨论】:
-
不确定你的意思,但我有管理员权限。 Jimmy Smith 为以下问题提供了解决方案。
标签: vb.net visual-studio shell ftp