Menu

#455 FTP should send \r\n when logging in

FTP
open
Zhang Ze
None
3
2022-11-29
2021-10-28
No

The AS400FTP object does not always send '\r\n' when sending the USERID and PASSWORD. The code should be changed so that the '\r\n' is always sent.

Specifically. the following code needs to be changed.

in AS400ImplRemote.java -- the writer.println should be changed to writer.print and the "\r\n" should be added. I also suspect that a flush will also be needed after the writer.print

// Get connection for FTP.
synchronized Socket getConnection(int port) throws IOException {
Socket socket = new Socket((systemNameLocal_) ? "localhost" : systemName_,
port);
try {
PortMapper.setSocketProperties(socket, socketProperties_);
BufferedReader reader = new BufferedReader(new InputStreamReader(
socket.getInputStream(), "ISO8859_1"));
PrintWriter writer = new PrintWriter(new OutputStreamWriter(
socket.getOutputStream(), "ISO8859_1"), true);

  readFTPLine(reader);

  writer.println("USER " + userId_);
  readFTPLine(reader);

  writer.println("PASS "

      + new String(BinaryConverter.byteArrayToCharArray(credVault_
          .getClearCredential())));
  if (!readFTPLine(reader).startsWith("230"))
    throw new IOException();

  return socket;
} catch (IOException e) {
  Trace.log(Trace.ERROR, "Establishing FTP connection failed:", e);
  try {
    socket.close();
  } catch (IOException ee) {
    Trace.log(Trace.ERROR, "Error closing socket:", ee);
  }
  throw e;
}

}

Discussion

  • John Eberhard

    John Eberhard - 2021-10-28
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,3 +1,42 @@
     The AS400FTP object does not always send '\r\n' when sending the USERID and PASSWORD. The code should be changed so that the '\r\n' is always sent. 
    
    -Specifically. 
    +Specifically.  the following code needs to be changed. 
    +
    +in AS400ImplRemote.java -- the writer.println should be changed to writer.print and the "\r\n" should be added.  I also suspect that a flush will also be needed after the writer.print
    +
    
    +  // Get connection for FTP.
    +  synchronized Socket getConnection(int port) throws IOException {
    +    Socket socket = new Socket((systemNameLocal_) ? "localhost" : systemName_,
    +        port);
    +    try {
    +      PortMapper.setSocketProperties(socket, socketProperties_);
    +      BufferedReader reader = new BufferedReader(new InputStreamReader(
    +          socket.getInputStream(), "ISO8859_1"));
    +      PrintWriter writer = new PrintWriter(new OutputStreamWriter(
    +          socket.getOutputStream(), "ISO8859_1"), true);
    +
    +      readFTPLine(reader);
    +
    +      writer.println("USER " + userId_);
    +      readFTPLine(reader);
    +
    +      writer.println("PASS "
    +          + new String(BinaryConverter.byteArrayToCharArray(credVault_
    +              .getClearCredential())));
    +      if (!readFTPLine(reader).startsWith("230"))
    +        throw new IOException();
    +
    +      return socket;
    +    } catch (IOException e) {
    +      Trace.log(Trace.ERROR, "Establishing FTP connection failed:", e);
    +      try {
    +        socket.close();
    +      } catch (IOException ee) {
    +        Trace.log(Trace.ERROR, "Error closing socket:", ee);
    +      }
    +      throw e;
    +    }
    +  }
    +
    +
    +
    
     
  • Zhang Ze

    Zhang Ze - 2022-11-29

    Fixed in JTOpen 11.1

     

Log in to post a comment.

MongoDB Logo MongoDB