0

我正在使用 Visual Studio 2012 并用 VB 编写。我想找到一种方法来启动批处理文件以进行 FTP 下载或上传,在 CMD 窗口中显示进度并将传输时间的结果记录到文本框中。

任何帮助表示赞赏。

FTP批处理脚本如下:

文件名:FT​​P_1M_Download.bat:

    @Echo off
    cd (Folder name here)
    ftp -s:FTP_1M_Download_s.bat

文件名:FT​​P_1M_Download_s.bat:

    open (FTP Address here)
    username
    password
    hash
    bin
    be
    get down_1M.zip
4

1 回答 1

0

这是我用来使用 ProcessStartInfo 运行 RoboCopy 的一些未经编辑的实用程序代码。它捕获输出流(在这种情况下,代码不会对它做任何事情。)

我使用 Kellerman SFTP 库——效果很好,而且不贵。

  Sub RunRobo(ByVal SD As String, ByVal DD As String, ByVal Job As String, ByRef Out As String, ByRef Err As String)
    ' runs RoboCopy and returns log text 
    ' typical job: "*.* /V /NDL /S /E /COPY:DAT /PURGE /NP /R:0 /W:0 "
    Try
        Application.DoEvents()
        Dim sParams As String = SD & " " & DD & " " & Job
        'If Not ShowHeadFoot Then sParams &= " /NJH /NJS"

        ' Set start information.
        Dim start_info As New ProcessStartInfo("RoboCopy", sParams)
        start_info.UseShellExecute = False
        start_info.CreateNoWindow = True
        start_info.RedirectStandardOutput = True
        start_info.RedirectStandardError = True

        ' Make the process and set its start information.
        Dim proc As New Process()
        proc.StartInfo = start_info

        ' Start the process.
        proc.Start()

        ' Attach to stdout and stderr.
        Dim std_out As System.IO.StreamReader = proc.StandardOutput()
        Dim std_err As System.IO.StreamReader = proc.StandardError()

        ' Display the results.
        Out = std_out.ReadToEnd()
        Err = std_err.ReadToEnd()

        'Dim aLines() As String = sOut.Split(vbCrLf) ' if no header/footer creates array of file info

        ' more generic would be to return via params
        'txtStreetsErr.Text = sErr
        'txtStreetsOut.Text = sOut

        Try
            std_out.Close()
            std_err.Close()
        Catch ex As Exception

        End Try
        Try
            proc.Close()
        Catch ex As Exception

        End Try

    Catch ex As Exception
        MsgBox(ex.Message, , "Error during RoboCopy")
    Finally
        'Cursor = Cursors.Default
    End Try
End Sub
于 2013-07-19T22:35:03.733 回答