FTP - Unix Permission Issues

coderdave12

New member
Joined
Nov 17, 2009
Messages
4
Programming Experience
Beginner
Hey All. Ok, I am trying to download a file from our Unix Server and I am using the code listed below. This works perfect when I am using the root credentials. Unforunantly, when I use normal crendentials it stops working on the response part, like it doesn't receive the message back. I know the normal login can FTP because I have used command line to test and it works fine. Also the directory has wide open permissions. The only thing I can tell is different is the default home directory, root is / and the normal user is nested down a few directories. Any thoughts? Thanks all


Imports System
Imports System.Net
Imports System.Data
Imports System.IO

Public Class Form1
Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click

Const localFile As String = "C:\test1\Readme.txt"
Const remoteFile As String = "/httpdocs/readme.txt"
Const host As String = "ftp://yourlinkhere"
Const username As String = "yourusernamehere"
Const password As String = "yourpasswordhere"

Dim URI As String = host & remoteFile
Dim ftp As System.Net.FtpWebRequest = _
CType(FtpWebRequest.Create(URI), FtpWebRequest)

ftp.Credentials = New _
System.Net.NetworkCredential(username, password)

ftp.KeepAlive = False

ftp.UseBinary = True

ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

Using response As System.Net.FtpWebResponse = _
CType(ftp.GetResponse, System.Net.FtpWebResponse)
Using responseStream As IO.Stream = response.GetResponseStream

Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0
responseStream.Close()
fs.Flush()
fs.Close()
End Using
responseStream.Close()
End Using
response.Close()
End Using

End Sub

End Class
 
What is the StatusCode of the FtpWebResponse ? You have to check this before doing GetResponseStream. Is the "/httpdocs/readme.txt" available from that users home dir?
 
I have created a work around but the problem is the home directory of the user I logged in as. This is why root works ok because the home directory is /. Is there any way I can issue a command that changes the directory? Or is there a way I can issue other Unix commands?
 
Any path available from the home dir can be specified with the url request, so this is where you have to set it, like "ftp://yourlinkhere/httpdocs/readme.txt" where "ftp://yourlinkhere" is the user root and "/httpdocs/readme.txt" is the relative path.
 
That should not be possible, it would normally be a configuration error with the server, but you could always try, it have to be specified in the url. ("ftp://yourlinkhere/../httpdocs/readme.txt")
 
No, that should not be possible.
 
Back
Top