Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2009

Tip: Looking for answers? Try searching our database.

ASP.NET FTP Not Downloading JPEGs Properly...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MU - 01 Apr 2009 14:14 GMT
Hello

I have this code and it downloads JPEGS from an FTP site that I am
using.  However, when I try to use ASPJPEG or another JPEG component,
it gives me an error saying that the file is corrupt.  How do I save
the file as a JPEG?

ASPJPEG Error:
Persits.Jpeg.1 error '80040035'
Not a JPEG file: starts with 0xef 0xbf

ASPThumb Error:
briz.AspThumb error '8000ffff'
Bitmap image is not valid

Here is the code:
               myFtpWebRequest = WebRequest.Create("ftp://
ftp.server.com/" & strFileName)
               myFtpWebRequest.Credentials = New NetworkCredential
("username", "password")
               myFtpWebRequest.Method =
WebRequestMethods.Ftp.DownloadFile
               myFtpWebRequest.UseBinary = True

               myFtpWebResponse = myFtpWebRequest.GetResponse()

               myStreamWriter = New StreamWriter(Server.MapPath("../
images/" & strFileName))
               myStreamWriter.Write(New StreamReader
(myFtpWebResponse.GetResponseStream()).ReadToEnd)
               myStreamWriter.Close()
               myFtpWebResponse.Close()

Thoughts?
Martin Honnen - 01 Apr 2009 14:49 GMT
> Hello
>
[quoted text clipped - 30 lines]
>
> Thoughts?

Why are you using a StreamReader and StreamWriter for binary image data?
Simply read chunks of bytes from the response stream and write them to a
file stream.

Or check whether WebClient can do it all for you with a simply method
call:
http://msdn.microsoft.com/en-us/library/system.net.webclient.downloadfile.aspx

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

MU - 01 Apr 2009 15:09 GMT
> > Hello
>
[quoted text clipped - 42 lines]
>         Martin Honnen --- MVP XML
>        http://JavaScript.FAQTs.com/

I need to FTP to the server to get the Image files.  Can I do what you
are suggesting with FTP?
Any hints on examples or how I would accomplish that?

Thanks
MU - 01 Apr 2009 15:37 GMT
> > > Hello
>
[quoted text clipped - 48 lines]
>
> Thanks

Here is the solution for anyone looking!

               Dim filename As String = "ftp://ftp.server.com/" &
strFileName
               Dim ftpReq As FtpWebRequest = WebRequest.Create
(filename)
               ftpReq.Method = WebRequestMethods.Ftp.DownloadFile
               ftpReq.Credentials = New NetworkCredential("username",
"password")

               Dim FTPResp As FtpWebResponse = ftpReq.GetResponse
               Dim ftpRespStream As Stream =
FTPResp.GetResponseStream

               Dim img As System.Drawing.Image =
System.Drawing.Image.FromStream(ftpRespStream)
               img.Save(Server.MapPath("../images/" & strFileName),
System.Drawing.Imaging.ImageFormat.Jpeg)
Martin Honnen - 01 Apr 2009 16:08 GMT
> Here is the solution for anyone looking!
>
[quoted text clipped - 14 lines]
>                 img.Save(Server.MapPath("../images/" & strFileName),
> System.Drawing.Imaging.ImageFormat.Jpeg)

WebClient should suffice

  Dim wc As New WebClient()
  wc.Credentials = New NetworkCredential("username",
"password")
  wc.DownloadFile("ftp://ftp.server.com/" &
strFileName, Server.MapPath("../images/" & strFileName))

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.