RE: FTP problems

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,
I am glad to know that finally you could get it working.

As far as calling the ".close()" function goes, for that you would need to
first make a stream object and close it as is given below

Using requestStream As System.IO.Stream = ftp.GetRequestStream()
'The rest of the code goes here
requestStream.Close()
End Using

And you got it right, the most of the problem was attributed to the fact
that the clean up was not being done properly.

regards,
Joy

"kpg" wrote:

Hi,
While going thru your code it appears to me that once you are done
with
writing the file you dont close the stream.

can you do a ".close()" on your stream and then try the code?

Let me know if the problem still persists.

regards,
Joy

I see your point. There are code examples out there
that create a stream variable and assign it the value
of ftp.GetRequestStream, then when complete they
close the stream. I perhaps incorrectly assumed that
the inplace GetRequestStream used below closed the stream
itself once completed.

Incidentally, as the code below does not use an explicit
stream object, how would it be closed in this case?

ftp.GetRequestStream().close ?

I would try it but I found a different solution that
works.

I replaced this:

Dim ftp As FtpWebRequest = _
CType(FtpWebRequest.Create(FTPPath),FtpWebRequest)
ftp.Credentials = New NetworkCredential(UserName,
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = WebRequestMethods.Ftp.UploadFile
ftp.GetRequestStream().Write(buffer, 0, buffer.Length)

with this:

Dim ftp As New WebClient
ftp.Credentials = New NetworkCredential(UserName, Password)
ftp.UploadData(FTPPath, buffer)

and that corrected the problem.

I have little doubt that either the stream (seems likely)
or something else was not being cleaned up properly, but
calling the higher level WebClient object's UploadData
method does any needed closing and cleanup for me.

When I searched for an ASP.NET 2.0 FTP examples I found
many using the ftpWebRequest object, but it took some
looking to discover the WebClient technique, which in
my mind is better because it works (!) and does so in
fewer lines of code.

I'm sure it uses the ftpWebRequest underneath, however.

Also in defense of the ftpWebRequest technique, most
examples used an explicit stream object that was then
closed in code, so that may well be the problem. I don't
noramlly like condensing the code down to one-liners
but in this case I did use that particular example.

Go Figure.

Thanks,
kpg



.



Relevant Pages

  • Re: ADO Stream Error
    ... When you open an unbound stream, there is no default so it must ... > CopyTo and none of the IStreams exposed by XML objects that I've seen ... > the Locals window to view the stream object as its initialized. ... > docs I'd guess the validity will depend on the type of the node. ...
    (microsoft.public.vb.database.ado)
  • Re: Closing ByteArrayOutputStreams
    ... when the method returns and the stream object goes out of scope, ... If your code doesn't "know" that it is writing to a ByteArrayOutputStream (e.g. ... Otherwise I wouldn't declare it with a more general type than ...
    (comp.lang.java.programmer)
  • Re: Trouble recreating ADO recordset from XML
    ... I use rst->Save to persist the data into a _Stream object. ... Meant to add, when opening a recordset on a persisted source, those options ... have you looked at the XML? ...
    (microsoft.public.data.ado)
  • Re: Search and replace inside a stream
    ... console.writeline returns the length of the stream has 88, ... string. ... the string is a completely separate object from what was in the ... I'm trying to search and replace the stream object in the most efficient ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: 8ms Timer for serial port access
    ... Then start calling readagain. ... stream of bytes that you acquire by calling read. ... Forget about timing. ... can read and be guaranteed that you have a complete frame). ...
    (comp.os.linux.development.apps)