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.
- 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
- Access the logs for this container either using Docker Desktop or
docker logs --follow <container ID> - Run this command on the container
ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pubto generate a ssh fingerprint.- You can run this in the Docker Desktop by accessing the container cli
- Or run it using
docker exec -it <container ID> <Command>
- 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
- 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
- To keep things simple
- Create your Request Body:
{
"responseItems": [
{
"returnQueueConsumerConfig": {
"queueName": "LCU.Queue.FTP",
"exchangeName": "LCU.FTP.Direct",
"subject": "LCU.Queue.FTP"
},
"returnQueueConnectionConfig": {
"Url" : "<QA Rabbitmq Server>",
"Port" : <QA Rabbit MQ Port>,
"Username" : "<FTP Username>",
"Password" : "<FTP Password>"
},
"ResponsePayload":"{\"test\":\"response\"}"
}
],
"protocol": 0,
"hostName": "<FirstnameLastname.lcu-internal.com>",
"portNumber": 22,
"userName": "demo",
"password": "demo",
"sshHostKeyFingerprint": "<Replace With Your Fingerprint>",
"remoteFilePath": "/sftp/test/test.txt",
"localFileData": "SGVsbG8gV29ybGQ="
}
- Post the /sftp request
- Monitor the RabbitMq LCU.Queue.FTP queue for a spike
- Monitor your Docker SFTP logs to see a remote login
- Monitor SEQ for the FTP API Environment you are using to see the success or fail message
- 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.