troubleshooting Question

uploading file to FTP fails

Avatar of Anthony Matovu
Anthony MatovuFlag for Uganda asked on
Visual Basic.NETWindows OS
3 Comments1 Solution765 ViewsLast Modified:
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()
ASKER CERTIFIED SOLUTION
Anthony Matovu
Business Analyst, MTN Uganda

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros