diff --git a/hw_13/.idea/modules/hw_13_main.iml b/hw_13/.idea/modules/hw_13_main.iml index 9d18387..5c96a5d 100644 --- a/hw_13/.idea/modules/hw_13_main.iml +++ b/hw_13/.idea/modules/hw_13_main.iml @@ -5,7 +5,6 @@ - diff --git a/hw_14/FtpServer.jar b/hw_14/FtpServer.jar old mode 100755 new mode 100644 index 2951b18..9bfabc6 Binary files a/hw_14/FtpServer.jar and b/hw_14/FtpServer.jar differ diff --git a/hw_14/FtpServer_old.jar b/hw_14/FtpServer_old.jar new file mode 100644 index 0000000..e69de29 diff --git a/hw_14/src/main/java/com/mikhail/pravilov/mit/ftpClient/model/FtpClient.java b/hw_14/src/main/java/com/mikhail/pravilov/mit/ftpClient/model/FtpClient.java index 13c4b7f..604ccb8 100644 --- a/hw_14/src/main/java/com/mikhail/pravilov/mit/ftpClient/model/FtpClient.java +++ b/hw_14/src/main/java/com/mikhail/pravilov/mit/ftpClient/model/FtpClient.java @@ -73,8 +73,8 @@ void close() throws IOException { */ @NotNull List> list(@NotNull Path path) throws IOException { - String command = "list " + path.toAbsolutePath().toString(); - dataOutputStream.writeUTF(command); + dataOutputStream.writeInt(1); + dataOutputStream.writeUTF(path.toAbsolutePath().toString()); dataOutputStream.flush(); int sizeOfList = dataInputStream.readInt(); List> listOfFiles = new LinkedList<>(); @@ -94,11 +94,14 @@ List> list(@NotNull Path path) throws IOException { * @throws IOException if error occurred during downloading and saving the file. */ void download(@NotNull Path pathToFile, @NotNull Path saveFilePath) throws IOException { - String command = "get " + pathToFile.toAbsolutePath().toString(); - dataOutputStream.writeUTF(command); + dataOutputStream.writeInt(2); + dataOutputStream.writeUTF(pathToFile.toAbsolutePath().toString()); dataOutputStream.flush(); long sizeOfFile = dataInputStream.readLong(); - OutputStream fileWriter = Files.newOutputStream(Files.createFile(saveFilePath)); + if (!saveFilePath.toFile().exists()) { + Files.createFile(saveFilePath); + } + OutputStream fileWriter = Files.newOutputStream(saveFilePath); byte[] buffer = new byte[2048]; for (long i = 0; i < sizeOfFile;) { int numberOfReadBytes = dataInputStream.read(buffer);