【问题标题】:How to send a file via FTP that is in the same folder as my program?如何通过与我的程序位于同一文件夹中的 FTP 发送文件?
【发布时间】:2017-11-19 04:21:13
【问题描述】:

我在互联网上找到了一个教程,该人展示了如何创建一种通过 FTP 将文件发送到服务器的完整方式,问题是:如何通过 FTP 发送位于同一程序文件夹中的文件?无需填写字段,只需一个按钮即可发送。

这是表格

这是此表单的代码

Private Sub BT_Upload_Click(sender As Object, e As EventArgs) Handles BT_Upload.Click
    My.Computer.Network.UploadFile(
        txtFile.Text, txtServer.Text & ofdBrowser.SafeFileName,
        txtUser.Text, txtPassword.Text)
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    If ofdBrowser.ShowDialog = DialogResult.OK Then
        txtFile.Text = ofdBrowser.FileName
    End If
End Sub

【问题讨论】:

    标签: .net vb.net ftp upload


    【解决方案1】:

    Application.StartupPath获取路径:

    Dim myFile As String = "myFile.txt"
    Dim fullFilePath As String = IO.Path.Combine(Application.StartupPath, myFile)
    My.Computer.Network.UploadFile(fullFilePath, ...)
    

    【讨论】:

      【解决方案2】:

      Get program path in VB.NET?

      Dim progPath As String = 
          System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath())
      Dim filePath = System.IO.Path.Combine(progPath, txtFile.Text)
      
      My.Computer.Network.UploadFile(filePath, ...)
      

      【讨论】:

        【解决方案3】:

        您可以轻松获取路径并像下面这样使用它:

        Private Sub BT_Upload_Click(sender As Object, e As EventArgs) Handles BT_Upload.Click
            Dim _filePath As String = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location) & "\" & txtFile.Text
            My.Computer.Network.UploadFile(
                _filePath, txtServer.Text & ofdBrowser.SafeFileName,
                txtUser.Text, txtPassword.Text)
        End Sub
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-02-10
          • 2016-11-24
          • 1970-01-01
          • 2012-07-15
          • 2013-02-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多