FtpWebRequest only has access to a specific folder

Ahren

Member
Joined
Nov 30, 2008
Messages
5
Programming Experience
Beginner
Hello,
I am currently using the below code to upload a file and display progress. It works fine except there are a few things I would like to do differently.
I am using the main FTP account for my website which has access to all of my files. I set up a different FTP login to use that only has access to a specific folder, but when I try to use it I get: Error 550 No such file or directory or access denied.

This FTP account allows access to: mywebsite.com/upload/users/ only
If strFTPAddress = mywebsite.com/upload/users/ I get error 550, I've tried a few other things too and it's told me that it's an invalid URI

Basically what I want to know is if and how I might be able to connect using my second FTP account so that I only have access to the upload/users/ directory.

VB.NET:
Dim request As FtpWebRequest = CType(WebRequest.Create(strFTPAddress & "/" & strNetFile), FtpWebRequest)

                request.Timeout = 10000000
                request.ReadWriteTimeout = 10000000
                request.KeepAlive = False
                request.UseBinary = True
                request.UsePassive = False

                request.Credentials = New System.Net.NetworkCredential(strUserName, strPassword)
                request.Method = WebRequestMethods.Ftp.UploadFile

                Dim fileContents() As Byte

                Using s As New FileStream(strLocalFileOnDisk, FileMode.Open, FileAccess.Read)
                    ReDim fileContents(CInt(s.Length - 1))
                    s.Read(fileContents, 0, CInt(s.Length))
                End Using

                request.ContentLength = fileContents.Length

                'Try
                Dim flags As Boolean = True
                Dim currentposition As Long = 0
                Dim len As Integer = 0
                Dim requestStream As Stream = request.GetRequestStream()

                Do While (flags)

                    lblStatus.Text = "Uploading..."

                    If ((fileContents.Length - currentposition) > 200) Then
                        len = 200
                    Else
                        len = fileContents.Length - currentposition
                    End If

                    requestStream.Write(fileContents, currentposition, len)
                    currentposition = currentposition + len

                    progBar.Value = Math.Round(currentposition * 100 / fileContents.Length, 1)
                    lblLoaded.Text = Math.Round(currentposition / 1024) & "/" & Math.Round(fileContents.Length / 1024) & "kb"
                    Application.DoEvents()

                    If (currentposition >= fileContents.Length) Then
                        flags = False
                    End If
                Loop

                requestStream.Close()

                Dim response As FtpWebResponse = CType(request.GetResponse(), FtpWebResponse)

                response.Close()
 
Have you tried connecting to the FTP site with ftp.exe? I'm going to assume you get a message that you don't have access to your home directory.
 
Im not sure how to explain this but i'll try.

When I connect to ftp normally I just use my ftp hostname
mywebsite.com

Depending on the username and password I put it I am given access to different directories. If I login using a user/pass combo that only lets me access mywebsite.com/upload/users/ that user's home directory is upload/users/

But when I put in the full path ftp://mywebsite.com/upload/users/ and the login info for just upload/users/ it doesn't know what to do with it and gives me an error
 
Im not sure how to explain this but i'll try.

When I connect to ftp normally I just use my ftp hostname
mywebsite.com

Depending on the username and password I put it I am given access to different directories. If I login using a user/pass combo that only lets me access mywebsite.com/upload/users/ that user's home directory is upload/users/

But when I put in the full path ftp://mywebsite.com/upload/users/ and the login info for just upload/users/ it doesn't know what to do with it and gives me an error

So you're saying it does fail when you try and access it using IE?
 
Since the user's home directory is ftp://mywebsite.com/upload/users/ they'll automatically be directed there when they log in.

Just use the root of your site and it will work.

Ran a quick test on my FTP server and it worked fine with a limited account.

So if your site is mywebsite.com just use ftp://mywebsite.com and if your ftp account is set up right it should work.
 
Back
Top