获得错误“远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限)。”使用WebRequestMethods.Ftp.DownloadFile时 [英] Getting error as "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)." while using WebRequestMethods.Ftp.DownloadFile

查看:734
本文介绍了获得错误“远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限)。”使用WebRequestMethods.Ftp.DownloadFile时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我正在开展一个项目,我需要使用FTP从物理路径下载附件。当我使用Filezilla客户端时,它正确下载。我也可以使用FTP命令下载文件。但是当我尝试访问文件并使用代码下载时,它给出错误远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限)。。请帮我解决这个问题。我编写了如下代码:



传递文件所在的目录名称和FileNM是我需要下载并附加到FTP路径的附件。代码如下:



Private Sub DownloadFTP(ByVal dirName As String,ByVal FileNM As String)

Dim uriPath As String = String。空

Dim serverUri As Uri = Nothing

Dim reqFTP As FtpWebRequest = Nothing

昏暗响应因为FtpWebResponse = Nothing

Dim responseStream As Stream = Nothing

Dim writeStream As FileStream = Nothing

Dim localdestn As String =c:\dir

Dim bufferSize As Integer = 4096

Dim Length As Integer = 2048

Dim buffer()By Byte = New Byte((Length)){}

Dim bytesRead As Integer = 0



尝试



uriPath =ftp:// itsusmp / DEFAULT /&dirName&/&FileNM

serverUri = New Uri(uriPath)

if serverUri.Scheme<> Uri.UriSchemeFtp然后

返回

结束如果

reqFTP = DirectCast(FtpWebRequest.Create(New Uri(uriPath)),FtpWebRequest)

reqFTP = CType(FtpWebRequest.Create(uriPath),FtpWebRequest)

reqFTP.Credentials = New NetworkCredential(adminusre,Pwd @ 2014)

Dim auth As String = reqFTP.AuthenticationLevel

reqFTP.KeepAlive = False

reqFTP.Method = WebRequestMethods.Ftp.DownloadFile

reqFTP。 UseBinary = True

reqFTP.Proxy = Nothing

reqFTP.UsePassive = False

response = DirectCast(reqFTP.GetResponse(),FtpWebResponse)

responseStream = response.GetResponseStream()

writeStream =新FileStream(localdestn&\&FileNM,FileMode.Create)

bytesRead = responseStream.Read(buffer,0,Length)

而bytesRead> 0

writeStream.Write(buffer,0,bytesRead)

bytesRead = responseStream.Read(buffer,0,Length)

结束时

writeStream.Close()

response.Close()



抓住webex作为WebException

扔掉webex

Catch ex As Exception

抛出ex

结束尝试

End Sub



如果出错,请帮助我。在此先感谢。



谢谢

TheRisingSun

Dear Friends,

Am working on a project where I need to download an attachment from a physical path using FTP. When am using Filezilla client , its downloading correctly.Also I am able to download file using FTP commands. But When I tried access file and download using code its giving error as "The remote server returned an error: (550) File unavailable (e.g., file not found, no access).". Please help me to resolve this issue. I have written code as follows:

Am passing directory name where file located and FileNM is attachment which I need to download and appending to FTP path . code is as follows:

Private Sub DownloadFTP(ByVal dirName As String, ByVal FileNM As String)
Dim uriPath As String = String.Empty
Dim serverUri As Uri = Nothing
Dim reqFTP As FtpWebRequest = Nothing
Dim response As FtpWebResponse = Nothing
Dim responseStream As Stream = Nothing
Dim writeStream As FileStream = Nothing
Dim localdestn As String = "c:\dir"
Dim bufferSize As Integer = 4096
Dim Length As Integer = 2048
Dim buffer() As Byte = New Byte((Length)) {}
Dim bytesRead As Integer = 0

Try

uriPath = "ftp://itsusmp/DEFAULT/" & dirName & "/" & FileNM
serverUri = New Uri(uriPath)
If serverUri.Scheme <> Uri.UriSchemeFtp Then
Return
End If
reqFTP = DirectCast(FtpWebRequest.Create(New Uri(uriPath)), FtpWebRequest)
reqFTP = CType(FtpWebRequest.Create(uriPath), FtpWebRequest)
reqFTP.Credentials = New NetworkCredential("adminusre", "Pwd@2014")
Dim auth As String = reqFTP.AuthenticationLevel
reqFTP.KeepAlive = False
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile
reqFTP.UseBinary = True
reqFTP.Proxy = Nothing
reqFTP.UsePassive = False
response = DirectCast(reqFTP.GetResponse(), FtpWebResponse)
responseStream = response.GetResponseStream()
writeStream = New FileStream(localdestn & "\" & FileNM, FileMode.Create)
bytesRead = responseStream.Read(buffer, 0, Length)
While bytesRead > 0
writeStream.Write(buffer, 0, bytesRead)
bytesRead = responseStream.Read(buffer, 0, Length)
End While
writeStream.Close()
response.Close()

Catch webex As WebException
Throw webex
Catch ex As Exception
Throw ex
End Try
End Sub

Please help me where am going wrong. Thanks in advance.

Thanks
TheRisingSun

推荐答案

这篇关于获得错误“远程服务器返回错误:(550)文件不可用(例如,找不到文件,没有访问权限)。”使用WebRequestMethods.Ftp.DownloadFile时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆