# Introduction FTP API is used for making HTTP requests to transfer files over SFTP. Consumers can submit byte[] directly, or a shared directory path. # Getting Started The required environment is .NET Core 3.1, Git, and something to work with C#. ## Working With The Code Before submitting your pull request, review the following: * Did you commit with a commitizen style message? * Did you add all needed unit testing, and ensure all existing tests are passing? * Make sure you didn't accidentally commit any secrets or passwords. # Contribute Please propose contributions to shared libraries and APIs; especially breaking changes. # Usage The easiest way to see usage is to look at the Integration test project which has sample code, or hit the QA swagger. TODO -> someone explain the shared file paths? # Testing the API You can use the following method to test the API locally or in any of the live environments. This method of testing will only test the SSH strategy. To use the WINSCP strategy would require a known file on the QA server. 1. Start a SFTP Docker Server with the following command on your local machine: `docker run -p 22:22 -d emberstack/sftp --name sftp` - This will create a simple SFTP server with the username: **demo** and password: **demo** - The working directory will be /sftp - You can access this through your computers full name which can be found in your PCs properties - It should follow this format: FirstnameLastname.lcu-internal.com 2. Access the logs for this container either using Docker Desktop or `docker logs --follow ` 3. Run this command on the container `ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub` to generate a ssh fingerprint. * You can run this in the Docker Desktop by accessing the container cli * Or run it using `docker exec -it ` 4. The command will generate a fingerprint that looks something like this: - 4096 SHA256:7bxdtxb2niicuigfdrobojrsashnlwid6/jA9puDY80 root@984e6ac2415f (RSA) - Reformat yours to match this pattern: - `ssh-rsa 4096 7bxdtxb2niicuigfdrobojrsashnlwid6/jA9puDY80` 5. Create a file you wish to transfer and convert its contents to bytes - To keep things simple `SGVsbG8gV29ybGQ=` should be de-serialize to the sentence "Hello World", you can use this as your file contents 6. Create your Request Body: ``` { "responseItems": [ { "returnQueueConsumerConfig": { "queueName": "LCU.Queue.FTP", "exchangeName": "LCU.FTP.Direct", "subject": "LCU.Queue.FTP" }, "returnQueueConnectionConfig": { "Url" : "", "Port" : , "Username" : "", "Password" : "" }, "ResponsePayload":"{\"test\":\"response\"}" } ], "protocol": 0, "hostName": "", "portNumber": 22, "userName": "demo", "password": "demo", "sshHostKeyFingerprint": "", "remoteFilePath": "/sftp/test/test.txt", "localFileData": "SGVsbG8gV29ybGQ=" } ``` 7. Post the /sftp request 8. Monitor the RabbitMq LCU.Queue.FTP queue for a spike 9. Monitor your Docker SFTP logs to see a remote login 10. Monitor SEQ for the FTP API Environment you are using to see the success or fail message 11. Verify that /sft/test/text.txt exists in your sftp server files You can modify this process and the request body to Fein success and failure and monitor the relevant success and failure queues as well. **Note**: If you are receiving the following errror `System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.` in the SEQ logs. This is not a problem with your code, but something wrong with the SFTP server you are hosting. Ensure you have no other applications running on port 22 on your machine.