/*** * Same as calling sendFile(filename, mode, input, host, TFTP.DEFAULT_PORT). * * @param filename The name the remote server should use when creating * the file on its file system. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param input the input stream containing the data to be sent * @param host The name of the remote host receiving the file. * @throws IOException If an I/O error occurs. The nature of the * error will be reported in the message. * @throws UnknownHostException If the hostname cannot be resolved. ***/ public void sendFile(String filename, int mode, InputStream input, InetAddress host) throws IOException { sendFile(filename, mode, input, host, DEFAULT_PORT); }
/*** * Same as calling receiveFile(filename, mode, output, host, TFTP.DEFAULT_PORT). * * @param filename The name of the file to receive. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param output The OutputStream to which the file should be written. * @param host The remote host serving the file. * @return number of bytes read * @throws IOException If an I/O error occurs. The nature of the * error will be reported in the message. ***/ public int receiveFile(String filename, int mode, OutputStream output, InetAddress host) throws IOException { return receiveFile(filename, mode, output, host, DEFAULT_PORT); }
beginBufferedOps(); bufferedSend(sent); // start the fetch/send an ack boolean wantReply = true; int timeouts = 0; do { // until successful response try { TFTPPacket received = bufferedReceive(); recdPort, TFTPErrorPacket.UNKNOWN_TID, "INCORRECT SOURCE PORT"); bufferedSend(error); throw new IOException("Incorrect source port ("+recdPort+") in request reply."); TFTPErrorPacket.OUT_OF_SPACE, "File write failed."); bufferedSend(error); throw e; discardPackets(); if (lastBlock == (block == 0 ? 65535 : (block - 1))) { wantReply = false; // Resend last acknowledgemen TFTPErrorPacket.UNKNOWN_TID, "Unexpected host or port."); bufferedSend(error); totalBytesReceived += dataLength; } while (dataLength == TFTPPacket.SEGMENT_SIZE); // not eof
try { inputStream = new FileInputStream(file); tftp = new TFTPClient(); tftp.open(); tftp.sendFile(remoteFileName, TFTP.BINARY_MODE, inputStream, hostName); } catch (Exception exp) { throw new RuntimeException(exp); try { if (tftp != null) { tftp.close();
TFTPDataPacket data = new TFTPDataPacket(host, port, 0, _sendBuffer, 4, 0); beginBufferedOps(); bufferedSend(sent); boolean wantReply = true; int timeouts = 0; do { try { TFTPPacket received = bufferedReceive(); final InetAddress recdAddress = received.getAddress(); final int recdPort = received.getPort(); recdPort, TFTPErrorPacket.UNKNOWN_TID, "INCORRECT SOURCE PORT"); bufferedSend(error); throw new IOException("Incorrect source port ("+recdPort+") in request reply."); discardPackets(); TFTPErrorPacket.UNKNOWN_TID, "Unexpected host or port."); bufferedSend(error); } while (true); // loops until after lastAckWait is set } finally { endBufferedOps();
beginBufferedOps(); bufferedSend(sent); received = bufferedReceive(); break; endBufferedOps(); throw new IOException("Connection timed out."); endBufferedOps(); throw new IOException("Connection timed out."); endBufferedOps(); throw new IOException("Bad packet: " + e.getMessage()); endBufferedOps(); throw new IOException("Error code " + error.getError() + " received: " + error.getMessage()); TFTPErrorPacket.OUT_OF_SPACE, "File write failed."); bufferedSend(error); endBufferedOps(); throw e; discardPackets(); endBufferedOps();
/*** * Same as calling sendFile(filename, mode, input, hostname, TFTP.DEFAULT_PORT). * * @param filename The name the remote server should use when creating * the file on its file system. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param input the input stream containing the data to be sent * @param hostname The name of the remote host receiving the file. * @throws IOException If an I/O error occurs. The nature of the * error will be reported in the message. * @throws UnknownHostException If the hostname cannot be resolved. ***/ public void sendFile(String filename, int mode, InputStream input, String hostname) throws UnknownHostException, IOException { sendFile(filename, mode, input, InetAddress.getByName(hostname), DEFAULT_PORT); } }
/*** * Same as calling receiveFile(filename, mode, output, hostname, TFTP.DEFAULT_PORT). * * @param filename The name of the file to receive. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param output The OutputStream to which the file should be written. * @param hostname The name of the remote host serving the file. * @return number of bytes read * @throws IOException If an I/O error occurs. The nature of the * error will be reported in the message. * @throws UnknownHostException If the hostname cannot be resolved. ***/ public int receiveFile(String filename, int mode, OutputStream output, String hostname) throws UnknownHostException, IOException { return receiveFile(filename, mode, output, InetAddress.getByName(hostname), DEFAULT_PORT); }
beginBufferedOps(); bufferedSend(sent); received = bufferedReceive(); break; endBufferedOps(); throw new IOException("Connection timed out."); endBufferedOps(); throw new IOException("Connection timed out."); endBufferedOps(); throw new IOException("Bad packet: " + e.getMessage()); endBufferedOps(); throw new IOException("Error code " + error.getError() + " received: " + error.getMessage()); discardPackets(); endBufferedOps(); throw new IOException("Received unexpected packet type."); TFTPErrorPacket.UNKNOWN_TID, "Unexpected host or port."); bufferedSend(error); continue _sendPacket;
/*** * Requests to send a file to a remote host, reads the file from an * InputStream, sends the file to the remote host, and closes the * connection. A local UDP socket must first be created by * {@link org.apache.commons.net.DatagramSocketClient#open open()} before * invoking this method. This method will not close the InputStream * containing the file; you must close it after the method invocation. * * @param filename The name the remote server should use when creating * the file on its file system. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param input the input stream containing the data to be sent * @param hostname The name of the remote host receiving the file. * @param port The port number of the remote TFTP server. * @throws IOException If an I/O error occurs. The nature of the * error will be reported in the message. * @throws UnknownHostException If the hostname cannot be resolved. ***/ public void sendFile(String filename, int mode, InputStream input, String hostname, int port) throws UnknownHostException, IOException { sendFile(filename, mode, input, InetAddress.getByName(hostname), port); }
/*** * Requests a named file from a remote host, writes the * file to an OutputStream, closes the connection, and returns the number * of bytes read. A local UDP socket must first be created by * {@link org.apache.commons.net.DatagramSocketClient#open open()} before * invoking this method. This method will not close the OutputStream * containing the file; you must close it after the method invocation. * * @param filename The name of the file to receive. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param output The OutputStream to which the file should be written. * @param hostname The name of the remote host serving the file. * @param port The port number of the remote TFTP server. * @return number of bytes read * @throws IOException If an I/O error occurs. The nature of the * error will be reported in the message. * @throws UnknownHostException If the hostname cannot be resolved. ***/ public int receiveFile(String filename, int mode, OutputStream output, String hostname, int port) throws UnknownHostException, IOException { return receiveFile(filename, mode, output, InetAddress.getByName(hostname), port); }
beginBufferedOps(); bufferedSend(sent); received = bufferedReceive(); break; endBufferedOps(); throw new IOException("Connection timed out."); endBufferedOps(); throw new IOException("Connection timed out."); endBufferedOps(); throw new IOException("Bad packet: " + e.getMessage()); endBufferedOps(); throw new IOException("Error code " + error.getError() + " received: " + error.getMessage()); TFTPErrorPacket.OUT_OF_SPACE, "File write failed."); bufferedSend(error); endBufferedOps(); throw e; discardPackets(); endBufferedOps();
/*** * Same as calling sendFile(filename, mode, input, host, TFTP.DEFAULT_PORT). * * @param filename The name the remote server should use when creating * the file on its file system. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param host The name of the remote host receiving the file. * @exception IOException If an I/O error occurs. The nature of the * error will be reported in the message. * @exception UnknownHostException If the hostname cannot be resolved. ***/ public void sendFile(String filename, int mode, InputStream input, InetAddress host) throws IOException { sendFile(filename, mode, input, host, DEFAULT_PORT); }
/*** * Same as calling receiveFile(filename, mode, output, host, TFTP.DEFAULT_PORT). * * @param filename The name of the file to receive. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param output The OutputStream to which the file should be written. * @param host The remote host serving the file. * @exception IOException If an I/O error occurs. The nature of the * error will be reported in the message. ***/ public int receiveFile(String filename, int mode, OutputStream output, InetAddress host) throws IOException { return receiveFile(filename, mode, output, host, DEFAULT_PORT); }
beginBufferedOps(); bufferedSend(sent); received = bufferedReceive(); break; endBufferedOps(); throw new IOException("Connection timed out."); endBufferedOps(); throw new IOException("Connection timed out."); endBufferedOps(); throw new IOException("Bad packet: " + e.getMessage()); endBufferedOps(); throw new IOException("Error code " + error.getError() + " received: " + error.getMessage()); discardPackets(); endBufferedOps(); throw new IOException("Received unexpected packet type."); TFTPErrorPacket.UNKNOWN_TID, "Unexpected host or port."); bufferedSend(error); continue _sendPacket;
/*** * Same as calling sendFile(filename, mode, input, host, TFTP.DEFAULT_PORT). * * @param filename The name the remote server should use when creating * the file on its file system. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param host The name of the remote host receiving the file. * @exception IOException If an I/O error occurs. The nature of the * error will be reported in the message. * @exception UnknownHostException If the hostname cannot be resolved. ***/ public void sendFile(String filename, int mode, InputStream input, InetAddress host) throws IOException { sendFile(filename, mode, input, host, DEFAULT_PORT); }
/*** * Same as calling receiveFile(filename, mode, output, host, TFTP.DEFAULT_PORT). * * @param filename The name of the file to receive. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param output The OutputStream to which the file should be written. * @param host The remote host serving the file. * @exception IOException If an I/O error occurs. The nature of the * error will be reported in the message. ***/ public int receiveFile(String filename, int mode, OutputStream output, InetAddress host) throws IOException { return receiveFile(filename, mode, output, host, DEFAULT_PORT); }
/*** * Same as calling sendFile(filename, mode, input, hostname, TFTP.DEFAULT_PORT). * * @param filename The name the remote server should use when creating * the file on its file system. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param hostname The name of the remote host receiving the file. * @exception IOException If an I/O error occurs. The nature of the * error will be reported in the message. * @exception UnknownHostException If the hostname cannot be resolved. ***/ public void sendFile(String filename, int mode, InputStream input, String hostname) throws UnknownHostException, IOException { sendFile(filename, mode, input, InetAddress.getByName(hostname), DEFAULT_PORT); } }
/*** * Same as calling receiveFile(filename, mode, output, hostname, TFTP.DEFAULT_PORT). * * @param filename The name of the file to receive. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param output The OutputStream to which the file should be written. * @param hostname The name of the remote host serving the file. * @exception IOException If an I/O error occurs. The nature of the * error will be reported in the message. * @exception UnknownHostException If the hostname cannot be resolved. ***/ public int receiveFile(String filename, int mode, OutputStream output, String hostname) throws UnknownHostException, IOException { return receiveFile(filename, mode, output, InetAddress.getByName(hostname), DEFAULT_PORT); }
/*** * Same as calling sendFile(filename, mode, input, hostname, TFTP.DEFAULT_PORT). * * @param filename The name the remote server should use when creating * the file on its file system. * @param mode The TFTP mode of the transfer (one of the MODE constants). * @param hostname The name of the remote host receiving the file. * @exception IOException If an I/O error occurs. The nature of the * error will be reported in the message. * @exception UnknownHostException If the hostname cannot be resolved. ***/ public void sendFile(String filename, int mode, InputStream input, String hostname) throws UnknownHostException, IOException { sendFile(filename, mode, input, InetAddress.getByName(hostname), DEFAULT_PORT); } }