使用子文件夹名称中的空格下载FTP文件 [英] FTP file download with spaces in sub-folder name
问题描述
我在从ftp站点的子目录下载zip文件时遇到问题。
它适用于任何其他文件类型,即使子目录有空格。
如果子目录没有空格,则zip文件也能正常工作。
异常是远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限)。
Net.FtpWebResponse.StatusDescription =550访问被拒绝。
非常感谢
我的尝试:
I'm having a problem downloading zip files from a sub-dir of an ftp site.
It works with any other file type even if the sub-dir has spaces.
If the sub-dir has no spaces the zip file works fine too.
The Exception is "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."
Net.FtpWebResponse.StatusDescription = "550 Access is denied."
Many Thanks
What I have tried:
Public Shared Sub TempDownload()
Try
Dim ftpRoot As String = "ftp://10.0.0.99/"
Dim ftpUser As String = "FtpUserName"
Dim ftpPass As String = "FtpPassword"
Dim strMainFolder As String = "\\DOMAIN\FOLDER1"
Dim myFolder As String = "DEVELOPMENT HOME 948"
Dim myFile As String = "MyZipFileName.zip"
Dim reqFTP As Net.FtpWebRequest
Dim outputStream As New IO.FileStream(IO.Path.Combine(IO.Path.Combine(strMainFolder, myFolder), myFile), IO.FileMode.Create)
reqFTP = Net.FtpWebRequest.Create(New Uri(ftpRoot & myFolder & "/" & myFile))
reqFTP.Method = Net.WebRequestMethods.Ftp.DownloadFile
reqFTP.UseBinary = True
reqFTP.Credentials = New Net.NetworkCredential(ftpUser, ftpPass)
reqFTP.UsePassive = False
'=====
'### The exception occurs here
Dim response As Net.FtpWebResponse = DirectCast(reqFTP.GetResponse(), Net.FtpWebResponse)
'=====
Dim ftpStream As IO.Stream = response.GetResponseStream()
Dim cl As Long = response.ContentLength
Dim bufferSize As Integer = 2048
Dim readCount As Integer
Dim buffer As Byte() = New Byte(bufferSize - 1) {}
readCount = ftpStream.Read(buffer, 0, bufferSize)
While readCount > 0
outputStream.Write(buffer, 0, readCount)
readCount = ftpStream.Read(buffer, 0, bufferSize)
End While
ftpStream.Close()
outputStream.Close()
response.Close()
Catch ex As Net.WebException
MessageBox.Show(DirectCast(ex.Response, Net.FtpWebResponse).StatusDescription)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
推荐答案
这是从服务器发送的响应:
This is the response send from the server:
Net.FtpWebResponse.StatusDescription = "550 Access is denied."
很明显。您无权访问该文件或目录。
如果您可以直接访问服务器,请检查其中的权限。如果没有,请使用可以显示文件权限的FTP客户端(例如FileZilla)。
It is pretty clear. You don't have the rights to access the file or directory.
If you have direct access to the server, check the permissions there. If not, use a FTP client that can show file permissions (e.g. FileZilla).
这篇关于使用子文件夹名称中的空格下载FTP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!