Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
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
Posted
Updated 21-Nov-16 21:06pm

1 solution

This is the response send from the server:
Net.FtpWebResponse.StatusDescription = "550 Access is denied."

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).
 
Share this answer
 
Comments
AlexF185 22-Nov-16 4:52am    
Many Thanks Jochen Arndt.
I had checked the folder permissions and some files inside that folder. They were OK. I did not check the permissions of other files that the my system is trying to download within that same folder. It turns out that they are zip files generated by SQL Backup Master with their own permissions. In checking the inheritance though Windows still treats the permissions as inherited when they clearly aren't.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900