精华内容
下载资源
问答
  • tftp server

    2017-10-13 14:16:29
    tftp server可以提供设备远程服务,可用作服务端和客户端
  • TFTP Server

    2012-03-13 18:47:00
    Chapter5.TFTP Server Table of Contents 5.1. Why using a TFTP server5.2. How to install a TFTP server ?5.3. Xinetd Options5.3.1. Disable5.3.2. User5.3.3. Server5.3.4. Server_args5.3.4.1. Block Si.....

    Chapter 5. TFTP Server

    5.1. Why using a TFTP server

    It provides config files, bootstraps for PXE client.

    5.2. How to install a TFTP server ?

    In Mandrake Linux 8.1 the package is : tftp-server-0.17-7mdk. By default on Mandrake Linux 8.x, tftp server is launched from the xinetd server :

    service xinetd start

    The TFTP server sources can be downloaded here [6]

    5.3. Xinetd Options

    5.3.1. Disable

    If you want to enable the server, the disable parameter must be set to no.

    5.3.2. User

    Specify the user that launch the tftpd server. For security reasons you can set this parameter to nobody.

    5.3.3. Server

    The path to the daemon, tftpd or in.tftpd.

    5.3.4. Server_args

    5.3.4.1. Block Size option

    By default the tftp server negotiates with the client on the block size. Some tftp client are not able to handle the negotiation process. In this case you must tell the tftp server not to negotiate the block size using the -r blksize option.

    5.3.4.2. Size ahead of time option

    By default the tftp server negotiates with the client on the size ahead of time. Some tftp client are not able to handle the negotiation process. You can also prevent the tftp server to start the negotation on the timeout using the -r blksize option

    5.3.4.3. Timeout option

    By default the tftp server negotiates with the client on the timeout. Some tftp clients are not able to handle the negotiation process. You can disable the negotation on the size ahead of time using the -r tsize option.

    5.3.4.4. Chrooting option

    The -s /tftboot specify that our tftp server is chrooted to the tftpboot directory. So be careful when using the filename option in the file dhcpd.conf. It must be set to :

    filename "/PXEClient/pxelinux.0"

    and not to :

    filename "/tftpboot/PXEClient/pxelinux.0"

    5.4. Sample tftpd file

     

    	service tftp
    {
            disable                 = no
            socket_type             = dgram
            protocol                = udp
            instances               = 2
            wait                    = yes
            user                    = nobody
            server                  = /usr/sbin/in.tftpd
    #       server_args             = -r blksize -r tsize -r timeout -v -v -s /tftpboot
            server_args             = -v -v -s /tftpboot
    }
    
    

    转载于:https://www.cnblogs.com/RichardLee/archive/2012/03/13/2394313.html

    展开全文
  • TFTPServer

    2015-01-04 12:52:00
    package com.network.tftp; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for addit...
    package com.network.tftp;
    /*
     * Licensed to the Apache Software Foundation (ASF) under one or more
     * contributor license agreements.  See the NOTICE file distributed with
     * this work for additional information regarding copyright ownership.
     * The ASF licenses this file to You 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.
     */
    
    
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.PrintStream;
    import java.net.SocketTimeoutException;
    import java.util.HashSet;
    import java.util.Iterator;
    
    import org.apache.commons.net.io.FromNetASCIIOutputStream;
    import org.apache.commons.net.io.ToNetASCIIInputStream;
    import org.apache.commons.net.tftp.TFTP;
    import org.apache.commons.net.tftp.TFTPAckPacket;
    import org.apache.commons.net.tftp.TFTPDataPacket;
    import org.apache.commons.net.tftp.TFTPErrorPacket;
    import org.apache.commons.net.tftp.TFTPPacket;
    import org.apache.commons.net.tftp.TFTPPacketException;
    import org.apache.commons.net.tftp.TFTPReadRequestPacket;
    import org.apache.commons.net.tftp.TFTPWriteRequestPacket;
    
    /**
     * A fully multi-threaded tftp server. Can handle multiple clients at the same time. Implements RFC
     * 1350 and wrapping block numbers for large file support.
     *
     * To launch, just create an instance of the class. An IOException will be thrown if the server
     * fails to start for reasons such as port in use, port denied, etc.
     *
     * To stop, use the shutdown method.
     *
     * To check to see if the server is still running (or if it stopped because of an error), call the
     * isRunning() method.
     *
     * By default, events are not logged to stdout/stderr. This can be changed with the
     * setLog and setLogError methods.
     *
     * <p>
     * Example usage is below:
     *
     * <code>
     * public static void main(String[] args) throws Exception
     *  {
     *      if (args.length != 1)
     *      {
     *          System.out
     *                  .println("You must provide 1 argument - the base path for the server to serve from.");
     *          System.exit(1);
     *      }
     *
     *      TFTPServer ts = new TFTPServer(new File(args[0]), new File(args[0]), GET_AND_PUT);
     *      ts.setSocketTimeout(2000);
     *
     *      System.out.println("TFTP Server running.  Press enter to stop.");
     *      new InputStreamReader(System.in).read();
     *
     *      ts.shutdown();
     *      System.out.println("Server shut down.");
     *      System.exit(0);
     *  }
     *
     * </code>
     *
     *
     * @author <A HREF="mailto:daniel.armbrust.list@gmail.com">Dan Armbrust</A>
     * @since 2.0
     */
    
    public class TFTPServer implements Runnable
    {
        private static final int DEFAULT_TFTP_PORT = 69;
        public static enum ServerMode { GET_ONLY, PUT_ONLY, GET_AND_PUT; }
    
        private HashSet<TFTPTransfer> transfers_ = new HashSet<TFTPTransfer>();
        private volatile boolean shutdownServer = false;
        private TFTP serverTftp_;
        private File serverReadDirectory_;
        private File serverWriteDirectory_;
        private int port_;
        private Exception serverException = null;
        private ServerMode mode_;
    
        /* /dev/null output stream (default) */
        private static final PrintStream nullStream = new PrintStream(
                new OutputStream() {
                    @Override
                    public void write(int b){}
                    @Override
                    public void write(byte[] b) throws IOException {}
                    }
                );
    
        // don't have access to a logger api, so we will log to these streams, which
        // by default are set to a no-op logger
        private PrintStream log_;
        private PrintStream logError_;
    
        private int maxTimeoutRetries_ = 3;
        private int socketTimeout_;
        private Thread serverThread;
    
    
        /**
         * Start a TFTP Server on the default port (69). Gets and Puts occur in the specified
         * directories.
         *
         * The server will start in another thread, allowing this constructor to return immediately.
         *
         * If a get or a put comes in with a relative path that tries to get outside of the
         * serverDirectory, then the get or put will be denied.
         *
         * GET_ONLY mode only allows gets, PUT_ONLY mode only allows puts, and GET_AND_PUT allows both.
         * Modes are defined as int constants in this class.
         *
         * @param serverReadDirectory directory for GET requests
         * @param serverWriteDirectory directory for PUT requests
         * @param mode A value as specified above.
         * @throws IOException if the server directory is invalid or does not exist.
         */
        public TFTPServer(File serverReadDirectory, File serverWriteDirectory, ServerMode mode)
                throws IOException
        {
            this(serverReadDirectory, serverWriteDirectory, DEFAULT_TFTP_PORT, mode, null, null);
        }
    
        /**
         * Start a TFTP Server on the specified port. Gets and Puts occur in the specified directory.
         *
         * The server will start in another thread, allowing this constructor to return immediately.
         *
         * If a get or a put comes in with a relative path that tries to get outside of the
         * serverDirectory, then the get or put will be denied.
         *
         * GET_ONLY mode only allows gets, PUT_ONLY mode only allows puts, and GET_AND_PUT allows both.
         * Modes are defined as int constants in this class.
         *
         * @param serverReadDirectory directory for GET requests
         * @param serverWriteDirectory directory for PUT requests
         * @param mode A value as specified above.
         * @param log Stream to write log message to. If not provided, uses System.out
         * @param errorLog Stream to write error messages to. If not provided, uses System.err.
         * @throws IOException if the server directory is invalid or does not exist.
         */
        public TFTPServer(File serverReadDirectory, File serverWriteDirectory, int port, ServerMode mode,
                PrintStream log, PrintStream errorLog) throws IOException
        {
            port_ = port;
            mode_ = mode;
            log_ = (log == null ? nullStream: log);
            logError_ = (errorLog == null ? nullStream : errorLog);
            launch(serverReadDirectory, serverWriteDirectory);
        }
    
        /**
         * Set the max number of retries in response to a timeout. Default 3. Min 0.
         *
         * @param retries
         */
        public void setMaxTimeoutRetries(int retries)
        {
            if (retries < 0)
            {
                throw new RuntimeException("Invalid Value");
            }
            maxTimeoutRetries_ = retries;
        }
    
        /**
         * Get the current value for maxTimeoutRetries
         */
        public int getMaxTimeoutRetries()
        {
            return maxTimeoutRetries_;
        }
    
        /**
         * Set the socket timeout in milliseconds used in transfers. Defaults to the value here:
         * http://commons.apache.org/net/apidocs/org/apache/commons/net/tftp/TFTP.html#DEFAULT_TIMEOUT
         * (5000 at the time I write this) Min value of 10.
         */
        public void setSocketTimeout(int timeout)
        {
            if (timeout < 10)
            {
                throw new RuntimeException("Invalid Value");
            }
            socketTimeout_ = timeout;
        }
    
        /**
         * The current socket timeout used during transfers in milliseconds.
         */
        public int getSocketTimeout()
        {
            return socketTimeout_;
        }
    
        /*
         * start the server, throw an error if it can't start.
         */
        private void launch(File serverReadDirectory, File serverWriteDirectory) throws IOException
        {
            log_.println("Starting TFTP Server on port " + port_ + ".  Read directory: "
                    + serverReadDirectory + " Write directory: " + serverWriteDirectory
                    + " Server Mode is " + mode_);
    
            serverReadDirectory_ = serverReadDirectory.getCanonicalFile();
            if (!serverReadDirectory_.exists() || !serverReadDirectory.isDirectory())
            {
                throw new IOException("The server read directory " + serverReadDirectory_
                        + " does not exist");
            }
    
            serverWriteDirectory_ = serverWriteDirectory.getCanonicalFile();
            if (!serverWriteDirectory_.exists() || !serverWriteDirectory.isDirectory())
            {
                throw new IOException("The server write directory " + serverWriteDirectory_
                        + " does not exist");
            }
    
            serverTftp_ = new TFTP();
    
            // This is the value used in response to each client.
            socketTimeout_ = serverTftp_.getDefaultTimeout();
    
            // we want the server thread to listen forever.
            serverTftp_.setDefaultTimeout(0);
    
            serverTftp_.open(port_);
    
            serverThread = new Thread(this,"TftpServer");
            serverThread.setDaemon(true);
            serverThread.start();
        }
    
        @Override
        protected void finalize() throws Throwable
        {
            shutdown();
        }
    
        /**
         * check if the server thread is still running.
         *
         * @return true if running, false if stopped.
         * @throws Exception throws the exception that stopped the server if the server is stopped from
         *             an exception.
         */
        public boolean isRunning() throws Exception
        {
            if (shutdownServer && serverException != null)
            {
                throw serverException;
            }
            return !shutdownServer;
        }
    
        public void run()
        {
            try
            {
                while (!shutdownServer)
                {
                    TFTPPacket tftpPacket;
    
                    tftpPacket = serverTftp_.receive();
    
                    TFTPTransfer tt = new TFTPTransfer(tftpPacket);
                    synchronized(transfers_)
                    {
                        transfers_.add(tt);
                    }
    
                    Thread thread = new Thread(tt);
                    thread.setDaemon(true);
                    thread.start();
                }
            }
            catch (Exception e)
            {
                if (!shutdownServer)
                {
                    serverException = e;
                    logError_.println("Unexpected Error in TFTP Server - Server shut down! + " + e);
                }
            }
            finally
            {
                shutdownServer = true; // set this to true, so the launching thread can check to see if it started.
                if (serverTftp_ != null && serverTftp_.isOpen())
                {
                    serverTftp_.close();
                }
            }
        }
    
        /**
         * Stop the tftp server (and any currently running transfers) and release all opened network
         * resources.
         */
        public void shutdown()
        {
            shutdownServer = true;
    
            synchronized(transfers_)
            {
                Iterator<TFTPTransfer> it = transfers_.iterator();
                while (it.hasNext())
                {
                    it.next().shutdown();
                }
            }
    
            try
            {
                serverTftp_.close();
            }
            catch (RuntimeException e)
            {
                // noop
            }
    
            try {
                serverThread.join();
            } catch (InterruptedException e) {
                // we've done the best we could, return
            }
        }
    
        /*
         * An instance of an ongoing transfer.
         */
        private class TFTPTransfer implements Runnable
        {
            private TFTPPacket tftpPacket_;
    
            private boolean shutdownTransfer = false;
    
            TFTP transferTftp_ = null;
    
            public TFTPTransfer(TFTPPacket tftpPacket)
            {
                tftpPacket_ = tftpPacket;
            }
    
            public void shutdown()
            {
                shutdownTransfer = true;
                try
                {
                    transferTftp_.close();
                }
                catch (RuntimeException e)
                {
                    // noop
                }
            }
    
            public void run()
            {
                try
                {
                    transferTftp_ = new TFTP();
    
                    transferTftp_.beginBufferedOps();
                    transferTftp_.setDefaultTimeout(socketTimeout_);
    
                    transferTftp_.open();
    
                    if (tftpPacket_ instanceof TFTPReadRequestPacket)
                    {
                        handleRead(((TFTPReadRequestPacket) tftpPacket_));
                    }
                    else if (tftpPacket_ instanceof TFTPWriteRequestPacket)
                    {
                        handleWrite((TFTPWriteRequestPacket) tftpPacket_);
                    }
                    else
                    {
                        log_.println("Unsupported TFTP request (" + tftpPacket_ + ") - ignored.");
                    }
                }
                catch (Exception e)
                {
                    if (!shutdownTransfer)
                    {
                        logError_
                                .println("Unexpected Error in during TFTP file transfer.  Transfer aborted. "
                                        + e);
                    }
                }
                finally
                {
                    try
                    {
                        if (transferTftp_ != null && transferTftp_.isOpen())
                        {
                            transferTftp_.endBufferedOps();
                            transferTftp_.close();
                        }
                    }
                    catch (Exception e)
                    {
                        // noop
                    }
                    synchronized(transfers_)
                    {
                        transfers_.remove(this);
                    }
                }
            }
    
            /*
             * Handle a tftp read request.
             */
            private void handleRead(TFTPReadRequestPacket trrp) throws IOException, TFTPPacketException
            {
                InputStream is = null;
                try
                {
                    if (mode_ == ServerMode.PUT_ONLY)
                    {
                        transferTftp_.bufferedSend(new TFTPErrorPacket(trrp.getAddress(), trrp
                                .getPort(), TFTPErrorPacket.ILLEGAL_OPERATION,
                                "Read not allowed by server."));
                        return;
                    }
    
                    try
                    {
                        is = new BufferedInputStream(new FileInputStream(buildSafeFile(
                                serverReadDirectory_, trrp.getFilename(), false)));
                    }
                    catch (FileNotFoundException e)
                    {
                        transferTftp_.bufferedSend(new TFTPErrorPacket(trrp.getAddress(), trrp
                                .getPort(), TFTPErrorPacket.FILE_NOT_FOUND, e.getMessage()));
                        return;
                    }
                    catch (Exception e)
                    {
                        transferTftp_.bufferedSend(new TFTPErrorPacket(trrp.getAddress(), trrp
                                .getPort(), TFTPErrorPacket.UNDEFINED, e.getMessage()));
                        return;
                    }
    
                    if (trrp.getMode() == TFTP.NETASCII_MODE)
                    {
                        is = new ToNetASCIIInputStream(is);
                    }
    
                    byte[] temp = new byte[TFTPDataPacket.MAX_DATA_LENGTH];
    
                    TFTPPacket answer;
    
                    int block = 1;
                    boolean sendNext = true;
    
                    int readLength = TFTPDataPacket.MAX_DATA_LENGTH;
    
                    TFTPDataPacket lastSentData = null;
    
                    // We are reading a file, so when we read less than the
                    // requested bytes, we know that we are at the end of the file.
                    while (readLength == TFTPDataPacket.MAX_DATA_LENGTH && !shutdownTransfer)
                    {
                        if (sendNext)
                        {
                            readLength = is.read(temp);
                            if (readLength == -1)
                            {
                                readLength = 0;
                            }
    
                            lastSentData = new TFTPDataPacket(trrp.getAddress(), trrp.getPort(), block,
                                    temp, 0, readLength);
                            transferTftp_.bufferedSend(lastSentData);
                        }
    
                        answer = null;
    
                        int timeoutCount = 0;
    
                        while (!shutdownTransfer
                                && (answer == null || !answer.getAddress().equals(trrp.getAddress()) || answer
                                        .getPort() != trrp.getPort()))
                        {
                            // listen for an answer.
                            if (answer != null)
                            {
                                // The answer that we got didn't come from the
                                // expected source, fire back an error, and continue
                                // listening.
                                log_.println("TFTP Server ignoring message from unexpected source.");
                                transferTftp_.bufferedSend(new TFTPErrorPacket(answer.getAddress(),
                                        answer.getPort(), TFTPErrorPacket.UNKNOWN_TID,
                                        "Unexpected Host or Port"));
                            }
                            try
                            {
                                answer = transferTftp_.bufferedReceive();
                            }
                            catch (SocketTimeoutException e)
                            {
                                if (timeoutCount >= maxTimeoutRetries_)
                                {
                                    throw e;
                                }
                                // didn't get an ack for this data. need to resend
                                // it.
                                timeoutCount++;
                                transferTftp_.bufferedSend(lastSentData);
                                continue;
                            }
                        }
    
                        if (answer == null || !(answer instanceof TFTPAckPacket))
                        {
                            if (!shutdownTransfer)
                            {
                                logError_
                                        .println("Unexpected response from tftp client during transfer ("
                                                + answer + ").  Transfer aborted.");
                            }
                            break;
                        }
                        else
                        {
                            // once we get here, we know we have an answer packet
                            // from the correct host.
                            TFTPAckPacket ack = (TFTPAckPacket) answer;
                            if (ack.getBlockNumber() != block)
                            {
                                /*
                                 * The origional tftp spec would have called on us to resend the
                                 * previous data here, however, that causes the SAS Syndrome.
                                 * http://www.faqs.org/rfcs/rfc1123.html section 4.2.3.1 The modified
                                 * spec says that we ignore a duplicate ack. If the packet was really
                                 * lost, we will time out on receive, and resend the previous data at
                                 * that point.
                                 */
                                sendNext = false;
                            }
                            else
                            {
                                // send the next block
                                block++;
                                if (block > 65535)
                                {
                                    // wrap the block number
                                    block = 0;
                                }
                                sendNext = true;
                            }
                        }
                    }
                }
                finally
                {
                    try
                    {
                        if (is != null)
                        {
                            is.close();
                        }
                    }
                    catch (IOException e)
                    {
                        // noop
                    }
                }
            }
    
            /*
             * handle a tftp write request.
             */
            private void handleWrite(TFTPWriteRequestPacket twrp) throws IOException,
                    TFTPPacketException
            {
                OutputStream bos = null;
                try
                {
                    if (mode_ == ServerMode.GET_ONLY)
                    {
                        transferTftp_.bufferedSend(new TFTPErrorPacket(twrp.getAddress(), twrp
                                .getPort(), TFTPErrorPacket.ILLEGAL_OPERATION,
                                "Write not allowed by server."));
                        return;
                    }
    
                    int lastBlock = 0;
                    String fileName = twrp.getFilename();
    
                    try
                    {
                        File temp = buildSafeFile(serverWriteDirectory_, fileName, true);
                        if (temp.exists())
                        {
                            transferTftp_.bufferedSend(new TFTPErrorPacket(twrp.getAddress(), twrp
                                    .getPort(), TFTPErrorPacket.FILE_EXISTS, "File already exists"));
                            return;
                        }
                        bos = new BufferedOutputStream(new FileOutputStream(temp));
    
                        if (twrp.getMode() == TFTP.NETASCII_MODE)
                        {
                            bos = new FromNetASCIIOutputStream(bos);
                        }
                    }
                    catch (Exception e)
                    {
                        transferTftp_.bufferedSend(new TFTPErrorPacket(twrp.getAddress(), twrp
                                .getPort(), TFTPErrorPacket.UNDEFINED, e.getMessage()));
                        return;
                    }
    
                    TFTPAckPacket lastSentAck = new TFTPAckPacket(twrp.getAddress(), twrp.getPort(), 0);
                    transferTftp_.bufferedSend(lastSentAck);
    
                    while (true)
                    {
                        // get the response - ensure it is from the right place.
                        TFTPPacket dataPacket = null;
    
                        int timeoutCount = 0;
    
                        while (!shutdownTransfer
                                && (dataPacket == null
                                        || !dataPacket.getAddress().equals(twrp.getAddress()) || dataPacket
                                        .getPort() != twrp.getPort()))
                        {
                            // listen for an answer.
                            if (dataPacket != null)
                            {
                                // The data that we got didn't come from the
                                // expected source, fire back an error, and continue
                                // listening.
                                log_.println("TFTP Server ignoring message from unexpected source.");
                                transferTftp_.bufferedSend(new TFTPErrorPacket(dataPacket.getAddress(),
                                        dataPacket.getPort(), TFTPErrorPacket.UNKNOWN_TID,
                                        "Unexpected Host or Port"));
                            }
    
                            try
                            {
                                dataPacket = transferTftp_.bufferedReceive();
                            }
                            catch (SocketTimeoutException e)
                            {
                                if (timeoutCount >= maxTimeoutRetries_)
                                {
                                    throw e;
                                }
                                // It didn't get our ack. Resend it.
                                transferTftp_.bufferedSend(lastSentAck);
                                timeoutCount++;
                                continue;
                            }
                        }
    
                        if (dataPacket != null && dataPacket instanceof TFTPWriteRequestPacket)
                        {
                            // it must have missed our initial ack. Send another.
                            lastSentAck = new TFTPAckPacket(twrp.getAddress(), twrp.getPort(), 0);
                            transferTftp_.bufferedSend(lastSentAck);
                        }
                        else if (dataPacket == null || !(dataPacket instanceof TFTPDataPacket))
                        {
                            if (!shutdownTransfer)
                            {
                                logError_
                                        .println("Unexpected response from tftp client during transfer ("
                                                + dataPacket + ").  Transfer aborted.");
                            }
                            break;
                        }
                        else
                        {
                            int block = ((TFTPDataPacket) dataPacket).getBlockNumber();
                            byte[] data = ((TFTPDataPacket) dataPacket).getData();
                            int dataLength = ((TFTPDataPacket) dataPacket).getDataLength();
                            int dataOffset = ((TFTPDataPacket) dataPacket).getDataOffset();
    
                            if (block > lastBlock || (lastBlock == 65535 && block == 0))
                            {
                                // it might resend a data block if it missed our ack
                                // - don't rewrite the block.
                                bos.write(data, dataOffset, dataLength);
                                lastBlock = block;
                            }
    
                            lastSentAck = new TFTPAckPacket(twrp.getAddress(), twrp.getPort(), block);
                            transferTftp_.bufferedSend(lastSentAck);
                            if (dataLength < TFTPDataPacket.MAX_DATA_LENGTH)
                            {
                                // end of stream signal - The tranfer is complete.
                                bos.close();
    
                                // But my ack may be lost - so listen to see if I
                                // need to resend the ack.
                                for (int i = 0; i < maxTimeoutRetries_; i++)
                                {
                                    try
                                    {
                                        dataPacket = transferTftp_.bufferedReceive();
                                    }
                                    catch (SocketTimeoutException e)
                                    {
                                        // this is the expected route - the client
                                        // shouldn't be sending any more packets.
                                        break;
                                    }
    
                                    if (dataPacket != null
                                            && (!dataPacket.getAddress().equals(twrp.getAddress()) || dataPacket
                                                    .getPort() != twrp.getPort()))
                                    {
                                        // make sure it was from the right client...
                                        transferTftp_
                                                .bufferedSend(new TFTPErrorPacket(dataPacket
                                                        .getAddress(), dataPacket.getPort(),
                                                        TFTPErrorPacket.UNKNOWN_TID,
                                                        "Unexpected Host or Port"));
                                    }
                                    else
                                    {
                                        // This means they sent us the last
                                        // datapacket again, must have missed our
                                        // ack. resend it.
                                        transferTftp_.bufferedSend(lastSentAck);
                                    }
                                }
    
                                // all done.
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    if (bos != null)
                    {
                        bos.close();
                    }
                }
            }
    
            /*
             * Utility method to make sure that paths provided by tftp clients do not get outside of the
             * serverRoot directory.
             */
            private File buildSafeFile(File serverDirectory, String fileName, boolean createSubDirs)
                    throws IOException
            {
                File temp = new File(serverDirectory, fileName);
                temp = temp.getCanonicalFile();
    
                if (!isSubdirectoryOf(serverDirectory, temp))
                {
                    throw new IOException("Cannot access files outside of tftp server root.");
                }
    
                // ensure directory exists (if requested)
                if (createSubDirs)
                {
                    createDirectory(temp.getParentFile());
                }
    
                return temp;
            }
    
            /*
             * recursively create subdirectories
             */
            private void createDirectory(File file) throws IOException
            {
                File parent = file.getParentFile();
                if (parent == null)
                {
                    throw new IOException("Unexpected error creating requested directory");
                }
                if (!parent.exists())
                {
                    // recurse...
                    createDirectory(parent);
                }
    
                if (parent.isDirectory())
                {
                    if (file.isDirectory())
                    {
                        return;
                    }
                    boolean result = file.mkdir();
                    if (!result)
                    {
                        throw new IOException("Couldn't create requested directory");
                    }
                }
                else
                {
                    throw new IOException(
                            "Invalid directory path - file in the way of requested folder");
                }
            }
    
            /*
             * recursively check to see if one directory is a parent of another.
             */
            private boolean isSubdirectoryOf(File parent, File child)
            {
                File childsParent = child.getParentFile();
                if (childsParent == null)
                {
                    return false;
                }
                if (childsParent.equals(parent))
                {
                    return true;
                }
                else
                {
                    return isSubdirectoryOf(parent, childsParent);
                }
            }
        }
    
        /**
         * Set the stream object to log debug / informational messages. By default, this is a no-op
         *
         * @param log
         */
        public void setLog(PrintStream log)
        {
            this.log_ = log;
        }
    
        /**
         * Set the stream object to log error messsages. By default, this is a no-op
         *
         * @param logError
         */
        public void setLogError(PrintStream logError)
        {
            this.logError_ = logError;
        }
    }

     

    转载于:https://www.cnblogs.com/wellla/p/4200847.html

    展开全文
  • tftp server 源码

    2016-08-10 21:34:03
    tftp server 源码
  • Cisco TFTP server

    2018-12-09 11:27:24
    Cisco TFTP server 电脑与思科设备直接的文件传输,汉化,支持win10 操作系统。
  • TFTPServer.zip

    2020-10-29 21:36:23
    适用于个人建立专用的tftp服务器用于文件的传输和管理等操作,有了他就可以快速建立tftp服务器了,小编为大家带来的是TFTP Server汉化,方便网络管理员使用。
  • Cisco TFTP Server

    2016-05-04 10:53:46
    TFTP Server,用来上传固件到防火墙。
  • SolarWinds TFTP Server

    2016-03-02 16:57:28
    SolarWinds TFTP Server 提供大部份 TFTP 傳輸協定 如 檔案傳輸..等。
  • TFTP Server v2.1

    2019-11-03 04:17:29
    TFTP是TCP/IP协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂、开销不大的文件传输服务。通常用于更新网络设备的flash image。tftp server完全兼容RFC1350, RFC2347, RFC2349标准。
  • 锐捷TftpServer.rar

    2020-03-04 11:36:33
    比较好用的TFTPSERVER,锐捷自己制作合并的。。亲测可用几乎所有交换机设备。。。
  • TFTP SERVER FOR MAC

    2013-04-29 11:04:04
    TFTP SERVER FOR MAC, MOUNTAIN LION 已试
  • 搭建tftp server服务

    千次阅读 2019-06-04 17:38:24
    公司的网络设备出现bug,需要另外升级IOS解决问题,就搭建了一个tftp server。 实际过去做类似操作,都是PC上本地打开tftp软件,但如果再IDC机房等环境,对线上设备升级时,还是使用规划的IP作为tftp server在访问上...

    公司的网络设备出现bug,需要另外升级IOS解决问题,就搭建了一个tftp server。

    实际过去做类似操作,都是PC上本地打开tftp软件,但如果再IDC机房等环境,对线上设备升级时,还是使用规划的IP作为tftp server在访问上更方便和规范。

    系统环境

    Ubuntu18.04

    安装

    #tftp服务器端
    apt-get install tftpd-hpa

    配置

    vim /etc/default/tftpd-hpa
    TFTP_USERNAME="tftp"
    #选择一个tftp根目录,权限设置777
    TFTP_DIRECTORY="/home/pyadmin/tftp-backup" 
    #设置监听地址
    TFTP_ADDRESS="0.0.0.0:69"
    TFTP_OPTIONS="-l -c -s"

    运行tftp服务

    /etc/init.d/tftpd-hpa start
    [ ok ] Starting tftpd-hpa (via systemctl): tftpd-hpa.service.
    /etc/init.d/tftpd-hpa status
    ● tftpd-hpa.service - LSB: HPA's tftp server
       Loaded: loaded (/etc/init.d/tftpd-hpa; generated)
       Active: active (running) since Mon 2019-05-13 02:10:40 UTC; 3 weeks 1 days ago
         Docs: man:systemd-sysv-generator(8)
        Tasks: 1 (limit: 4662)
       CGroup: /system.slice/tftpd-hpa.service
               └─1646 /usr/sbin/in.tftpd --listen --user tftp --address 0.0.0.0:69 -l -c -s /home/pyadmin/tftp-backup
    
    May 13 02:10:39 backup systemd[1]: Starting LSB: HPA's tftp server...
    May 13 02:10:39 backup tftpd-hpa[1529]:  * Starting HPA's tftpd in.tftpd
    May 13 02:10:40 backup tftpd-hpa[1529]:    ...done.
    May 13 02:10:40 backup systemd[1]: Started LSB: HPA's tftp server.

    转载于:https://blog.51cto.com/talk1985/2404961

    展开全文
  • Add v4 TFTP Server Support

    2020-12-27 14:27:22
    <div><h2>Adding V4 TFTP Server Support <p>V4 host addresses did not work due to always using AF_INET6 when binding the server socket. I was looking to use this in a environment where netbooting over ...
  • fedora安装tftp server

    2017-12-05 17:20:40
    由于要在板子上实现tftp client, 所以现在pc实现tftp server, 直接用sudo dnf install tftp-server安装,显示搜不到package,所以从网上下载了安装包,...2.安装完之后,server的目录

    由于要在板子上实现tftp client, 所以现在pc实现tftp server, 直接用sudo dnf install tftp-server安装,显示搜不到package,所以从网上下载了安装包,https://fedora.pkgs.org/26/fedora-x86_64/tftp-server-5.2-20.fc26.x86_64.rpm.html
    2.安装完之后,server的目录为/var/lib/tftpboot目录。
    3.使用tftp命令 : 
    a. tftp 127.0.0.1
    b. put file //可以将当前目录传到服务器目录
    c. get file  //从服务器目录获取某个文件
    在b步骤时,会出现不能找到文件的错误,这是因为tftp一般只支持从服务器获取文件,如果要向服务器推送文件,也必须在服务器目录下有这个文件,然后你用推送的文件覆盖它。所以,需要在服务器目录下创建同名的文件,将其mode设置为777,然后就可以覆盖了。

    3.查看tftp是否启动:
    netstat -a | grep tftp
    4.enable tftp
    sudo systemctl enable tftp
    5.start tftp
    sudo systemctl restart tftp
    4.一般需要关闭本机防火墙
    sudo systemctl stop firewalld.service

    展开全文
  • 使用TFTP Server

    千次阅读 2012-02-20 20:25:10
    学会使用TFTP Server。 1.2 实验内容 l 了解TFTP Server的意义; l 学习如何使用TFTP Server来保存路由器上flash及startup-config等配置文件; l 学习如何通过TFTP Server来载入保存则配置文件; 1.3 实验...
  • 学会使用TFTP Server。 1.2实验内容 l 了解TFTP Server的意义; l 学习如何使用TFTP Server来保存路由器上flash及startup-config等配置文件; l 学习如何通过TFTP Server来载入保存则配置文件; 1.3实验步骤...
  • tftp-架設 tftp server

    千次阅读 2013-04-21 22:33:41
    前言 簡單來說,我們在 Linux 上面架設 tftp server,方便於相關設備 (例如 Switch、Router) 將「設...CentOS 6.2 (Linux 2.6.32-71.el6.i686)tftp servertftp-server-0.49-7.el6.i686tftp client: tftp-0.49-7
  • TFTP server组态

    2015-08-10 09:50:00
    TFTP server组态 2014-10-31北京海淀区张俊浩 一、TFTP(Trivial File Transfer Protocol,简单文件传输协议或称小型文件传输协议) 是一种简化的文件传输协议,于1980年定义,TCP/IP协议族中的一个用来在客户机...
  • redhat tftp server配置

    2016-10-01 10:59:50
    打开/etc/xinetd.d/tftp目录,文件中内容如下 ...# description: The tftp server serves files using the trivial file transfer \ # protocol. The tftp protocol is often used to boot diskless \ # worksta
  • Ubuntu 14.04 安装 tftp server 1. 安装  sudo apt-get install tftp-hpa tftpd-hpa xinetd 2. mkdir /home/obama/tftpboot  chmod 777 tftpboot 3. 配置  vim /etc/default/tftp-hpa ===
  • <p>TFTP clients are timing out on connection to the server which supports my hypothesis. I am new to linux and thinstation so please help.</p><p>该提问来源于开源项目:Thinstation/thinstation</p>...
  • cisco tftp server

    2009-09-21 20:57:00
    Cisco TFTP Server(设备软件升级必备工具
  • tftp server.rar

    2020-03-28 13:09:19
    这个是Cisco的TFTP服务。用于其三层交换机和路由器导出配置时配合使用。但是这个程序不但能够在Cisco,也可用于H3C和华为等设备。
  • TftpServer for Mac

    2018-07-14 06:13:52
    MAC下免费的TFTP服务器软件,MACOS 11下测试通过。MAC下免费的TFTP服务器软件,MACOS 11下测试通过。MAC下免费的TFTP服务器软件,MACOS 11下测试通过。MAC下免费的TFTP服务器软件,MACOS 11下测试通过。
  • ubuntu安装tftp server

    2014-08-25 16:33:14
    ubuntu安装tftp server   1、安装相关软件包 apt-get install tftpd (服务端) apt-get install tftp (客户端) apt-get install xinetd 2、建立配置文件 cd /etc/xinetd.d/ vitftp (/etc/xinetd.d/tftp...
  • TftpServer.exe

    2019-11-15 14:55:31
    对应想要通过TFTP下载资源的人而言,这个软件省去了复杂的配置过程,只要启动,服务端的配置就不需要自己来配置,只要知道另一端的IP地址就能实现数据的传送
  • it request the tftp files from the dhcp server and not the tftp server. If I do not set this menu text, the Raspberry pi is just retrying sending dhcp discoveries. What am I doing wrong? <p>tcpdump ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 3,164
精华内容 1,265
关键字:

tftpserver