uploading file to FTP fails

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()
LVL 1
Anthony MatovuBusiness Analyst, MTN UgandaAsked:
Who is Participating?
 
Anthony MatovuBusiness Analyst, MTN UgandaAuthor Commented:
Thank you members, i had an issue in my address, i removed the "//" , instead of "ftp://ftpuser@10.156.146.16//PAKAPAKA/" i did "ftp://ftpuser@10.156.146.16/PAKAPAKA/"

and it worked
Anthony
0
 
Éric MoreauSenior .Net ConsultantCommented:
well the message is pretty clear. The filename is not valid.

Have you tried something as simple as:
ftp.UploadFile(csvFile, "ftp://ftpuser@10.156.146.16//PAKAPAKA/test.txt")

Open in new window

1
 
Anthony MatovuBusiness Analyst, MTN UgandaAuthor Commented:
I solved the problem
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.