Hi Clinton,
Clearer than mud! ;-)
Okay, assuming that we're talking about an XML file generated by a web
application (websiteA), and assuming that websiteB is hosted on a web server
that shares the directories with an FTP server on serverB, it should not be
a problem, except for possible security (firewall) issues.
If using .Net platform 2.0, you can use the System.Net.FtpWebRequest and
System.Net.FtpWebResponse classes to upload the file from websiteA to the
FTP server on websiteB.
I'm not crazy about these 2 classes (even though they work pretty well), as
they mimic the behavior of HttpWebRequest and HttpWebResponse, even though
under the covers, so to speak, they are doing something entirely different,
such as maintaining an opened Connection. I suppose this was a decision by
some Microsoft designer or architect who figured having 2 distinctly
different behavior models might confuse our pretty little heads. But as you
know, I'm all about personal responsibility, and believe that software
should have a programming interface that behaves the way it does. If the
developer understands nothing about the underlying protocol, he/she needs to
before he/she starts writing code. I'm all for productivity tools, but
enhancing productivity and enabling laziness and willful ignorance are 2
entirely different things, with 2 entirely opposite values.
The HttpWebRequest and HttpWebResponse classes are designed specifically to
work in and mimic the stateless "single Request/Response" model of HTTP. The
FtpWebRequest and FtpWebResponse classes are designed to work in a connected
client/server Session, but to behave as if they are working in a stateless
"Single Request/Response" situation, which they are not working in. For this
reason, if you understand much about FTP, the object model is
counter-intuitive. Of course, if you're an ignoramous, it seems perfectly
logical. But heaven help you if things don't work the way you expect,
because being an ignoramous, you will not know why, or what to do about it!
In particular, downloading files with th FtpWebRequest class is not hard at
all, but uploading them is somewhat cryptic. The reason? To upload a file,
you must create a Network Stream, and write the file to it, after agreeing
with the server on the port to send the stream to. This is all carefully
hidden in the FtpWebRequest class, and if something goes wrong, due to the
object model, it's awfully hard to figure out what. In many cases, it works
without any issues at all. In a few, you're in deep trouble.
This is why I ended up writing my own FTP client socket-based classes that
mirror the behavior of an actual FTP session, and can even log the entire
message exchange, as well as socket-related information. But that isn't
going to help you any at this point!
That said, they do the job. You may need to read a few articles to help you
learn how to use them:
http://blogs.msdn.com/adarshk/archive/category/7225.aspx
http://blogs.msdn.com/adarshk/archive/2004/09/13/229069.aspx
http://geekswithblogs.net/mikeymac/archive/2006/03/10/71990.aspx
In addition, here are a few pointers:
Most FTP servers that allow file uploads require a login. Be sure to use
NetworkCredentials with your FtpWebRequest to make sure that it logs in with
the correct credentials.
The key to uploading is in the FtpWebRequest.GetRequestStream method. This
encapsulates the messaging that is exchanged to set up the port to send to
on the remote server. The NetworkStream returned is actually pointing to the
Stream Socket that will be written to.
You will want to convert your XML document to a stream to upload it.
Use Passive FTP mode to ensure that firewall issues are minimized (long
story).
Be aware of potential firewall issues. FTP uses 2 connections for uploading
and downloading. Port 21 on the remote server is not likely to be an issue,
but could be. However, your client will attempt to use other ports to
transfer data. This is why you use Passive mode, since if the client on this
side of the firewall specifies a port, most firewalls will allow incoming
connections on that port.
I think that's about it. Be sure to come back if you have any problems.
--
HTH,
Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist
I recycle.
I send everything back to the planet it came from.