Results 1 to 9 of 9

Thread: FtpWebRequest only has access to a specific folder

  1. #1
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Nov 2008
    Posts
    5
    Reputation
    0

    FtpWebRequest only has access to a specific folder

    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.

    Code:
    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()

  2. #2
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2008
    Location
    WY, USA
    Posts
    1,206
    Reputation
    636
    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.

  3. #3
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Nov 2008
    Posts
    5
    Reputation
    0
    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

  4. #4
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2008
    Location
    WY, USA
    Posts
    1,206
    Reputation
    636
    Quote Originally Posted by Ahren View Post
    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?

  5. #5
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Nov 2008
    Posts
    5
    Reputation
    0
    With IE or my Firefox FTP add-on I have no problems at all

  6. #6
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2008
    Location
    WY, USA
    Posts
    1,206
    Reputation
    636
    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.

  7. #7
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Nov 2008
    Posts
    5
    Reputation
    0
    Wow that's all I had to do for it to work Thanks Matt

  8. #8
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Aug 2009
    Posts
    5
    Reputation
    0
    Hi,

    Would you please tell me what you did because I have the same problem. Thanks!

    Acheo

  9. #9
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Nov 2008
    Posts
    5
    Reputation
    0
    Quote Originally Posted by MattP View Post
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •