Vb.net – ftp file transfer using vb.net without any third party tools

ftpftpwebrequestvb.net

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

Best Answer

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.

Related Topic