使用vb.net进行ftp文件传输,无需任何第三方工具

发布于 2025-01-08 12:14:43 字数 1167 浏览 1 评论 0原文

我正在使用 vb.net 编写代码,用于从远程计算机到本地计算机的文件传输,而不使用任何第三方工具

这是我的代码

Dim reqFTP As FtpWebRequest
    Dim filepath As String
    Dim filename As String
    Dim filename1 As String
    Dim ftpserverip As String
    Dim ftpuserid As String
    Dim ftpPassword As String
    Try
        filename1 = TxtRemoteFile.Text
        filepath = TxtLocalFile.Text
        filename = Locfname.Text
        ftpserverip = TxtServerIP.Text
        ftpuserid = TxtUserName.Text
        ftpPassword = TxtPwd.Text
        Dim outputStream As FileStream = New FileStream((filepath + ("\\" + filename)), FileMode.Create)
        reqFTP = CType(FtpWebRequest.Create(New Uri(("ftp://" _
                            + (ftpserverip + ("/" + filename1))))), FtpWebRequest)
        reqFTP.Method = WebRequestMethods.Ftp.DownloadFile
        reqFTP.UseBinary = True
        reqFTP.Credentials = New NetworkCredential(ftpuserid, ftpPassword)
        Dim response As FtpWebResponse = CType(reqFTP.GetResponse, FtpWebResponse)

        outputStream.Close()

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

,但出现类似“远程服务器返回错误:(550) fi 的错误”

I am writing the code using vb.net for file transfer from remote machine to local machine with out using any third party tools

This my code

Dim reqFTP As FtpWebRequest
    Dim filepath As String
    Dim filename As String
    Dim filename1 As String
    Dim ftpserverip As String
    Dim ftpuserid As String
    Dim ftpPassword As String
    Try
        filename1 = TxtRemoteFile.Text
        filepath = TxtLocalFile.Text
        filename = Locfname.Text
        ftpserverip = TxtServerIP.Text
        ftpuserid = TxtUserName.Text
        ftpPassword = TxtPwd.Text
        Dim outputStream As FileStream = New FileStream((filepath + ("\\" + filename)), FileMode.Create)
        reqFTP = CType(FtpWebRequest.Create(New Uri(("ftp://" _
                            + (ftpserverip + ("/" + filename1))))), FtpWebRequest)
        reqFTP.Method = WebRequestMethods.Ftp.DownloadFile
        reqFTP.UseBinary = True
        reqFTP.Credentials = New NetworkCredential(ftpuserid, ftpPassword)
        Dim response As FtpWebResponse = CType(reqFTP.GetResponse, FtpWebResponse)

        outputStream.Close()

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

but am getting error like" remote server returned error :(550) fi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮筵 2025-01-15 12:14:43

我有同样的问题。我没有在远程路径中包含 httpdocs。
例子:
ftp://ftp.websitename.com/httpdocs/filenametocopy.txt

System.Net.WebRequest.Create("ftp://ftp.websitename.com/httpdocs/filenametocopy.txt")

权限被拒绝,因为我试图将文件写入根目录之外。

I had the same issue. I was not including httpdocs in the remote path.
Example:
ftp://ftp.websitename.com/httpdocs/filenametocopy.txt

System.Net.WebRequest.Create("ftp://ftp.websitename.com/httpdocs/filenametocopy.txt")

Permission was denied because i was trying to write the file outside the root directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文