[Mono-dev] Bug In Mono FTP System.Net.FtpWebRequest

Carlos Alberto Cortez calberto.cortez at gmail.com
Thu Sep 4 10:27:16 EDT 2008


This is mostly an eror. Please fill a bug for it. See 
http://mono-project.com/Bugs

Carlos.

El mié, 03-09-2008 a las 05:23 -0700, Dieuzorro escribió:
> 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
> > 
> > 
> 



More information about the Mono-devel-list mailing list