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?

1

There are 1 best solutions below

1
On

The argument of WebRequest.Create is an URL.

You are passing:

"directory" + Year + "\" + Month1 + "\" + todaysDate + ".csv"

That's clearly wrong.

  1. It's not URL. The URL has to start ftp://hostname. Though I assume that you actually have the ftp://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.
  2. You have to use forward slashes.

The URL has to be something like:

"ftp://ftp.example.com/directory/" + Year + "/" + Month1 + "/" + todaysDate + ".csv"