【问题标题】:"The remote server returned an error: (550) File unavailable (e.g., file not found, no access)" when uploading file to FTP server in VB.NET“远程服务器返回错误:(550)文件不可用(例如,找不到文件,无法访问)”在 VB.NET 中将文件上传到 FTP 服务器时
【发布时间】:2016-12-20 09:40:23
【问题描述】:

我很难理解这个错误的概念,因为我有以下信息:

' 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()

错误发生在以下行:

Dim strz As System.IO.Stream = request.GetRequestStream()

错误:

远程服务器返回错误:(550) 文件不可用(例如, 找不到文件,无法访问)VB.NET 错误

我输入的所有信息都是正确的,我只是在努力理解为什么这是错误的,因为我在网上找到了这个,其他人似乎都推荐它。如果有什么可以向我解释为什么?

【问题讨论】:

    标签: .net vb.net ftp ftpwebrequest


    【解决方案1】:

    WebRequest.Create 的参数是一个 URL。

    你正在通过:

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

    这显然是错误的。

    1. 这不是 URL。 URL 必须以ftp://hostname 开头。虽然我假设你实际上在那里有ftp://hostname,否则你会得到一个完全不同的错误。 如果你不向我们展示真正的代码,很难帮助你。
    2. 您必须使用正斜杠。

    URL 必须是这样的:

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

    【讨论】:

    • 修复了它,它不喜欢我出于某种原因在该位置创建子目录的事实,奇怪但它解决了问题!感谢您的帮助! :)
    猜你喜欢
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    • 1970-01-01
    相关资源
    最近更新 更多