« Return to Thread: Bug In Mono FTP System.Net.FtpWebRequest

Re: Bug In Mono FTP System.Net.FtpWebRequest

by Rafael Teixeira :: Rate this Message:

Reply to Author | View in Thread

Check that the FTP server isn't forcing Windows authentication, which isn't supported by Mono, you need a plain FTP server. MS IIS doesn't behave as a plain FTP server with its default configuration, AFAIK.

On Wed, Sep 3, 2008 at 9:23 AM, Dieuzorro <dieuzorro@...> wrote:

With my code I was able to download a file on the server
"ftp://ftp-developpez.com/konflor/Latex/formation/FormationLatex.pdf"
anonymously. But on my local server when I want to download a file with a
loggin and a password, my stream "ResponceStream" is empty and there is no
error. On Windows everything works.

     Have you got an exemple on mono which connect on an private ftp
server? But my code works on windows and ftp server!

   Thanks



Dieuzorro wrote:
>
>
>
>     The code below operates under windwos but not Linux file is created,
> but it is empty.
>
>     I think that the bug is in 'Credentials' because I can download files
> on server without authentication(Login/Password).
>
> Sorry for my English I am french
>
>
>
>
>     Sub dl(ByVal remoteFile As String, ByVal localFile As String, ByVal
> username As String, ByVal password As String)
>
>
>
>         '1. Create a request: must be in ftp://hostname format,
>
>         '   not just ftp.myhost.com
>
>         Dim URI As String = remoteFile
>
>         Dim ftp As System.Net.FtpWebRequest =
> CType(FtpWebRequest.Create(URI), FtpWebRequest)
>
>
>
>
>         '3. Settings and action
>
>         ftp.KeepAlive = False
>
>         'we want a binary transfer, not textual data
>
>         ftp.UseBinary = True
>
>         'Define the action required (in this case, download a file)
>
>         ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
>
>
>         '2. Set credentials
>         if not (username = "" andalso password = "") then
>
>               ftp.Credentials = New NetworkCredential( username, password)
>         end if
>
>
>         '4. If we were using a method that uploads data e.g. UploadFile
>
>         '   we would open the ftp.GetRequestStream here an send the data
>
>
>
>         '5. Get the response to the Ftp request and the associated stream
>
>         Using response As System.Net.FtpWebResponse =
> CType(ftp.GetResponse, System.Net.FtpWebResponse)
>
>             Using responseStream As IO.Stream = response.GetResponseStream
>
>                 'loop to read & write to file
>
>                 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 'see Note(1)
>
>                     responseStream.Close()
>
>                     fs.Flush()
>
>                     fs.Close()
>
>         End Using
>
>
>
>     End Sub         End Using
>
>                 responseStream.Close()
>
>             End Using
>
>             response.Close()
>
>         End Using
>
>
>
>     End Sub
>
>

--
View this message in context: http://www.nabble.com/Bug-In-Mono-FTP-System.Net.FtpWebRequest-tp19272346p19288162.html
Sent from the Mono - Dev mailing list archive at Nabble.com.

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@...
http://lists.ximian.com/mailman/listinfo/mono-devel-list



--
Rafael "Monoman" Teixeira
---------------------------------------
"I myself am made entirely of flaws, stitched together with good intentions."
Augusten Burroughs

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@...
http://lists.ximian.com/mailman/listinfo/mono-devel-list

 « Return to Thread: Bug In Mono FTP System.Net.FtpWebRequest