Visual Basic .NET Forums    

Go Back   Visual Basic .NET Forums > Components & Controls > Net / Sockets

VB.NET Forums Newsletter Signup:
Email address:


Net / Sockets Components for network and related use

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-30-2008, 7:55 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Nov 2008
Age: 19
Posts: 4
Reputation: 0
Ahren is on a distinguished programming path ahead
Default 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()
Reply With Quote
  #2 (permalink)  
Old 12-02-2008, 1:26 PM
VB.NET Forum Miyagee
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 431
Reputation: 89
MattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woods
Default

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.
Reply With Quote
  #3 (permalink)  
Old 12-02-2008, 3:59 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Nov 2008
Age: 19
Posts: 4
Reputation: 0
Ahren is on a distinguished programming path ahead
Default

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
Reply With Quote
  #4 (permalink)  
Old 12-02-2008, 4:43 PM
VB.NET Forum Miyagee
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 431
Reputation: 89
MattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woods
Default

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?
Reply With Quote
  #5 (permalink)  
Old 12-02-2008, 6:31 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Nov 2008
Age: 19
Posts: 4
Reputation: 0
Ahren is on a distinguished programming path ahead
Default

With IE or my Firefox FTP add-on I have no problems at all
Reply With Quote
  #6 (permalink)  
Old 12-03-2008, 12:26 PM
VB.NET Forum Miyagee
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 431
Reputation: 89
MattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woods
Default

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.
Reply With Quote
  #7 (permalink)  
Old 12-03-2008, 2:31 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Nov 2008
Age: 19
Posts: 4
Reputation: 0
Ahren is on a distinguished programming path ahead
Default

Wow that's all I had to do for it to work Thanks Matt
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 11:04 PM.




Click to advertise here

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
For advertising opportunities click here.