You might want to consider transferring the file from server a to server b over ssh protocol, using a secure file copy tool such as scp.
To prevent an attacker (such as an MITM) from impersonating server b, you can pin server b's public key on server a, by storing server b's public key in server a's
known_hosts file. When server a connects to server b to transfer the file, the ssh client on server a will verify that the the public key that server b presents is the same as the one pinned in the
known_hosts file, and that server a is in possession of the private key that matches this public key. This makes it extremely difficult for another server to impersonate server b.
To prevent an attacker from impersonating server a, you can store server a's public key in server b's
authorized_keys file, and configure the sshd server on server b to use public key based authentication, where it only allows connections from clients whose public keys are in the