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.NetworkCredenti
al
Private _logger As New Logging.AspLog
Sub New(ByVal username As String, ByVal password As String)
setNetworkCredentials(user
name, password)
End Sub
Public Sub UploadFile(ByVal _FileName As String, ByVal _UploadPath As String)
Dim _FileInfo As New System.IO.FileInfo(_FileNa
me)
Dim _FtpWebRequest As System.Net.FtpWebRequest = CType(System.Net.FtpWebReq
uest.Creat
e(New Uri(_UploadPath)), System.Net.FtpWebRequest)
_FtpWebRequest.Credentials
= _netcredentials
_FtpWebRequest.Proxy = Nothing
_FtpWebRequest.KeepAlive = False
_FtpWebRequest.Timeout = 20000
_FtpWebRequest.Method = System.Net.WebRequestMetho
ds.
Ftp.UploadFile
_FtpWebRequest.UseBinary = True
_FtpWebRequest.ContentLeng
th = _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.GetRequestS
tream()
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(ByVa
l username As String, ByVal password As String)
_netcredentials = New System.Net.NetworkCredenti
al(usernam
e, password)
End Sub
End Class
ftp.UploadFile(csvFile, "
ftp://ftpuser@10.156.146.16//PAKAPAKA/" & Trim(Mid(csvFile, csvFile.ToString.LastIndex
Of("\") + 2, 200)))
it fails at line Dim _Stream As System.IO.Stream = _FtpWebRequest.GetRequestS
tream()
Our community of experts have been thoroughly vetted for their expertise and industry experience.