如何通过FTP与我的程序在同一文件夹中发送文件?

时间:2017-11-19 04:21:13

标签: .net vb.net ftp upload

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

这是表格

enter image description here

以下是此表格的代码

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

3 个答案:

答案 0 :(得分:1)

获取Application.StartupPath的路径:

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

答案 1 :(得分:0)

请参阅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, ...)

答案 2 :(得分:0)

您可以轻松获取路径并使用它,如下所示:

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