I am struggling to understand the concept on this error as I have the following information:
' Year (For Folder Name)
Dim Year As String
Year = Date.Today.Year
' Month (For Folder Name)
Dim Month1 As String
Month1 = MonthName(Month(Now()), False)
' Current Date (For File Name)
Dim todaysDate As String
todaysDate = Date.Now.ToString("dd-MM-yyyy")
Dim request As System.Net.FtpWebRequest =
DirectCast(System.Net.WebRequest.Create(
"directory" + Year + "\" + Month1 + "\" + todaysDate + ".csv"),
System.Net.FtpWebRequest)
request.Credentials = New System.Net.NetworkCredential("user", "password")
request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
Console.WriteLine("Connected Successfully")
Dim file() As Byte = System.IO.File.ReadAllBytes(
"directory" + Year + "\" + Month1 + "\" + todaysDate + ".csv")
Dim strz As System.IO.Stream = request.GetRequestStream()
strz.Write(file, 0, file.Length)
strz.Close()
strz.Dispose()
The error occurs on the following line:
Dim strz As System.IO.Stream = request.GetRequestStream()
Error:
The remote server returned an error: (550) File unavailable (e.g., file not found, no access) VB.NET Error
All of the information that I have inputted is correct, I am just struggling to understand why this is error, as I have found this online and everyone else seems to recommend it. If anything could someone just explain to me why?
The argument of
WebRequest.Create
is an URL.You are passing:
That's clearly wrong.
ftp://hostname
. Though I assume that you actually have theftp://hostname
there, as you would get a totally different error otherwise. It's difficult to help you, if you are not showing us the real code.The URL has to be something like: