We help IT Professionals succeed at work.
Get Started

uploading file to FTP fails

753 Views
Last Modified: 2017-11-28
I am trying to upload a file to an ftp using vb.net but it fails with this message yet i can access and create/copy file to that ftp using windows explorer. Massage given is "The remote server returned an error: (553) File name not allowed".

Code i have is

  Public ftp As New FTPUtils("ftpuser", "*****")

    Public Class FTPUtils
        Private _netcredentials As System.Net.NetworkCredential
        Private _logger As New Logging.AspLog
        Sub New(ByVal username As String, ByVal password As String)
            setNetworkCredentials(username, password)
        End Sub
        Public Sub UploadFile(ByVal _FileName As String, ByVal _UploadPath As String)
            Dim _FileInfo As New System.IO.FileInfo(_FileName)
            Dim _FtpWebRequest As System.Net.FtpWebRequest = CType(System.Net.FtpWebRequest.Create(New Uri(_UploadPath)), System.Net.FtpWebRequest)
            _FtpWebRequest.Credentials = _netcredentials
            _FtpWebRequest.Proxy = Nothing
            _FtpWebRequest.KeepAlive = False
            _FtpWebRequest.Timeout = 20000
            _FtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
            _FtpWebRequest.UseBinary = True
            _FtpWebRequest.ContentLength = _FileInfo.Length
            Dim buffLength As Integer = 2048
            Dim buff(buffLength - 1) As Byte
            Dim _FileStream As System.IO.FileStream = _FileInfo.OpenRead()
            Try
                Dim _Stream As System.IO.Stream = _FtpWebRequest.GetRequestStream()
                Dim contentLen As Integer = _FileStream.Read(buff, 0, buffLength)
                Do While contentLen <> 0
                    _Stream.Write(buff, 0, contentLen)
                    contentLen = _FileStream.Read(buff, 0, buffLength)
                Loop
                _Stream.Close()
                _Stream.Dispose()
                _FileStream.Close()
                _FileStream.Dispose()
            Catch ex As Exception
                _logger.WriteEntry("Upload Error: " & ex.Message)
            End Try
        End Sub
        Private Sub setNetworkCredentials(ByVal username As String, ByVal password As String)
            _netcredentials = New System.Net.NetworkCredential(username, password)
        End Sub
    End Class


         ftp.UploadFile(csvFile, "ftp://ftpuser@10.156.146.16//PAKAPAKA/" & Trim(Mid(csvFile, csvFile.ToString.LastIndexOf("\") + 2, 200)))

it fails at line   Dim _Stream As System.IO.Stream = _FtpWebRequest.GetRequestStream()
Comment
Watch Question
Business Analyst, MTN Uganda
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE