FTP from one website to another?

C

clintonG

I'm puzzled and don't think this is possible but if an application that is
running on websiteA generates a file can FTP be used from websiteA to
transfer that file to websiteB which would be located on another server?
 
V

V

Hello,

Well it depends,

If it is the WebsiteA that is initiating the transfer to send the file
to WebsiteB, then the WebsiteB must be running an FTP Server.

If it is the WebsiteB that initiates the transfer to get the file from
WebsiteA, then WebsiteA must be running an FTP Server.

But it surely is possible.

- Vaibhav
 
K

Kevin Spencer

Hi Clinton,

Yes, under the correct circumstances. Forgive me if I tell you anything you
already know, as I don't know what you already know, so I'm going to start
at a comfortably low position and work my way up from there...

A web application is an application designed to run in a web server. A web
server is a server application that communicates with its clients via HTTP
(HyperText Transfer Protocol). This is a text-based messaging protocol which
runs on a TCP transport over the Internet, which sends text messages back
and forth between client and server, and can also be used to transmit binary
data as well.

FTP (File Transfer Protocol) is another text-based protocol that runs on a
TCP transport over the Internet. It also involves a server (an FTP server)
and multiple clients, which transmit requests and responses in text format,
and can be used to transmit both text and binary data between server and
client.

There are several differences between these 2 protocols. FTP is a
"connected" protocol. It maintains an open connection between the client and
the server (on the server port 21 usually) for the duration of a user
session. This "command connection" is used to exchange the requests and
responses between server and client, and separate connections are created on
different ports as needed to transfer files. HTTP is a "disconnected"
protocol, which can be configured to keep the underlying TCP connection
opened, or close it and reopen it with each request/response. Because of the
"disconnected" nature of HTTP, it is stateless. It only uses a single port
(usually Port 80) to transfer all messaging and data. FTP is older than
HTTP, and has several issues with firewalls and security that HTTP does not,
but both are generally pretty reliable, as TCP is a reliable networking
protocol. They use entirely different text "languages" to communicate. And
of course, although it is theoretically possible to create an FTP client
that can render HTML, and use FTP as the underlying protocol, FTP is not
used for this purpose, and is generally regarded as simply a mechanism for
transferring files 2 ways between client and server, whilt HTTP is generally
regarded as a one-way protocol in which the client is generally only
receiving files from the server.

Enough of that. Now down to the nitty gritty of what you were asking. Both
protocols require a server to listen and handle incoming client requests.
Both protocols can run on the same machine, and can work with the same
directories. So, it is quite possible, and even common for an HTTP web to
have FTP access. Many web designers use FTP to upload their files to the web
server. So, the only real question you need to ask is, does the web server
machine have an FTP server with access to the same files and folders as the
web site? If so, an application can use both FTP and HTTP to exchange data
and files between server and client.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

I recycle.
I send everything back to the planet it came from.
 
C

clintonG

Thanks for commenting...

<%= Clinton

V said:
Hello,

Well it depends,

If it is the WebsiteA that is initiating the transfer to send the file
to WebsiteB, then the WebsiteB must be running an FTP Server.

If it is the WebsiteB that initiates the transfer to get the file from
WebsiteA, then WebsiteA must be running an FTP Server.

But it surely is possible.

- Vaibhav
 
C

clintonG

Hello Kevin,

Thanks for the smedumacation ;-) I've never written any code that used FTP.
The concern here is ease of use and trying to provide a seamless transition
for a user on websiteA who will be using an application on websiteA that
will output an XML file that needs to be located somewhere under the root of
the user's website that I refer to as websiteB.

When the application on websiteA that generates the XML file is finished
doing so the application will ask the user if they want to see the XML file
in the browser to allow them to copy-paste or use File Save As to save to
their local file system. If they want to use a local instance of FTP to
transport the file to their website (websiteB) so be it -- or -- if
possible -- the application will ask the user to select a means to login to
websiteB from websiteA and use the application running on websiteA to
transport the file to websiteB.

I've never gotten close to any task like this. Is it clear as mud?

<%= Clinton
 
C

clintonG

Hello Kevin,

Thanks for the smedumacation ;-) I've never written any code that used FTP.
The concern here is ease of use and trying to provide a seamless transition
for a user on websiteA who will be using an application on websiteA that
will output an XML file that needs to be located somewhere under the root of
the user's website that I refer to as websiteB.

When the application on websiteA that generates the XML file is finished
doing so the application will ask the user if they want to see the XML file
in the browser to allow them to copy-paste or use File Save As to save to
their local file system. If they want to use a local instance of FTP to
transport the file to their website (websiteB) so be it -- or -- if
possible -- the application will ask the user to select a means to login to
websiteB from websiteA and use the application running on websiteA to
transport the file to websiteB.

I've never gotten close to any task like this. Is it clear as mud?

<%= Clinton
 
K

Kevin Spencer

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.
 
C

clintonG

Kevin, you've been a real gem over the years. Your response provides me with
helpful information and insight I'm sure you gained through much painful
trial and error. I'll get right into it...

<%= Clinton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top