Ftp Server

Only available on StudyMode
  • Topic: File Transfer Protocol, Computer file, FTPS
  • Pages : 41 (4247 words )
  • Download(s) : 324
  • Published : March 31, 2012
Open Document
Text Preview

///////////////////A program to demonstrate FTP server to Server communication. /*
 * Copyright 2001-2005 The Apache Software Foundation  *
 * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.

 */
package examples;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import org.apache.commons.net.ProtocolCommandListener;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;

/***
 * This is an example program demonstrating how to use the FTPClient class.  * This program arranges a server to server file transfer that transfers  * a file from host1 to host2.  Keep in mind, this program might only work  * if host2 is the same as the host you run it on (for security reasons,  * some ftp servers only allow PORT commands to be issued with a host  * argument equal to the client host).

 * 
 * Usage: ftp          * 
 ***/
public class server2serverFTP
{

    public static final void main(String[] args)
    {
        String server1, username1, password1, file1;         String server2, username2, password2, file2;         FTPClient ftp1, ftp2;
        ProtocolCommandListener listener;

        if (args.length 
        try
        {
            int reply;
            ftp1.connect(server1);
            System.out.println("Connected to " + server1 + ".");

            reply = ftp1.getReplyCode();

            if (!FTPReply.isPositiveCompletion(reply))             {
                ftp1.disconnect();
                System.err.println("FTP server1 refused connection.");                 System.exit(1);
            }
        }
        catch (IOException e)
        {
            if (ftp1.isConnected())
            {
                try
                {
                    ftp1.disconnect();
                }
                catch (IOException f)
                {
                    // do nothing
                }
            }
            System.err.println("Could not connect to server1.");             e.printStackTrace();
            System.exit(1);
        }

        try
        {
            int reply;
            ftp2.connect(server2);
            System.out.println("Connected to " + server2 + ".");

            reply = ftp2.getReplyCode();

            if (!FTPReply.isPositiveCompletion(reply))             {
                ftp2.disconnect();
                System.err.println("FTP server2 refused connection.");                 System.exit(1);
            }
        }
        catch (IOException e)
        {
            if (ftp2.isConnected())
            {
                try
                {
                    ftp2.disconnect();
                }...
tracking img