Transfer files from SFTP to FTP using scp command - scp

How can I transfer files from SFTP to FTP using the scp command?
I have tried this : scp -P21 /folder/file user#domaine.com:/folder
But it is not working! It gives that error:
connection lost

The scp command doesn't support the FTP protocol, so you'll need to use an FTP client.
The top answer to this question, "How to upload one file by FTP from command line?", suggests invoking the FTP client like this:
$ ftp -n <<EOF
open ftp.example.com
user user secret
put my-local-file.txt
EOF
That is, instruct the FTP client to connect to ftp.example.com, authenticate, and upload my-local-file.txt, all in a single shell command.

Related

Robot Framework - SSH library - Editing a file on remote server

I am writing a test case in Robot Framework where in, I have to either copy the file from the local machine (windows) to the remote server (linux) or create a new one at the location.
I have used multiple sudo su - command to switch users to root user to reach the desired host. As a result of this, I am not able to use Put File Keyword from SSH Library to upload the file. I have reached at the desired folder location by executing the commands with Write keyword.
Since there is no option left (thats what i realize with my limited knowledge on Robot Framework), i started creating a new file with vi <filename> command. I have also reached the INSERT mode of the file, BUT i am not able to edit text into the file.
Can someone please suggest me how can i either
Copy the file from local windows machine to remote linux server AFTER multiple SU commands (Switch User)
Create a new text file and enter the content.
Please See : the new file which is being created / copied is a certificate file. Hence i do not wish to write the entire content of the certificate in my test suite file
The entire test case looks something like this
First Jump1
Log Starting the connection to AWS VM
# Connection to VM with Public Key
Connection To VM ${hostname} ${username}
Send Command sudo su -
Send Command su - <ServiceUser1>
# Reached the Detination server
Send Command whoami
Send Command ss -tln | grep 127.0.0.1:40
# Connecting to Particular ZIP
Send Command sudo -u <ServiceUser2> /usr/bin/ssh <ServiceUser2>#localhost -p <port>
Send Command sudo su -
# Check Auth Certificate
Send Command mosquitto_pub -h ${mq_host} -p ${mq_port} -u ${mq_username} -P ${mq_password}
In the step Check Auth Certificate, the certificate is checked to be present or not, if present -> delete the current certificate and create the new one (either create a new file or upload from local) and if it not there create a new certificate
though it might not be ideal, but was able to achieve what i wanted to do with
echo "content" > newFilename
echo "update content" >> newFileName

Not able to connect (using ftp and command line with) server via pem file

I have instance id, public DNS IP address, .pem file. I tried to connect to an EC2 instance using FileZilla but each time it fails saying could not authenticate (server: public key sent).
How can I connect using filezilla to EC2 instance?
I have tried putty too but it also gives an error and can't let me log in.
When tried using command line ssh -i My.pem root#ec2-myipaddress.us-west-2.compute.amazonaws.com it also gives error Permission denied (public key).
ssh -i My.pem root#ec2-myipaddress.us-west-2.compute.amazonaws.com
Its give permission issue so first of all run below command
sudo chmod 400 My.pem
After that try to connect with ssh command
and for file transfer use winSCP Tool.
you can check here for more detail
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html
Thanks

Where do I find the spec for scp -t?

So I have discovered I can do the following with scp via stdin:
Directory creation
scp -tr .
stdin -> D0755 0 <directory_name>
stdin -> \x00
File writing
scp -tr .
stdin -> C<filemode, eg. 0744> <file_size_in_bytes> <filename>
stdin -> actual file bytes
stdin -> \x00
In the man pages I can't find any mention of this, nor have I had luck with googling. Where do I find the spec for these various commands: file creation, directory creation? What else can I do? I'm curious where this is defined. I'm struggling to find where I even found this code initially. Why is there no mention of the -t flag in the scp man page?
scp transfers files by opening an SSH connection to a remote server and invoking another copy of scp on the remote system. The two scp instances communicate through a simple protocol; one instance sends commands and file data; the other instance acts on the commands to store the files on its local system.
The -t option tells scp that it was invoked by another scp instance and that it'll be receiving files. There is another option -f which tells scp that it was invoked by another instance and should send files.
You'd have to ask the OpenSSH developers why the options aren't documented. One might presume that it's because they're not intended for use by humans and so not really part of the user interface.
The best online descriptions of the SCP protocol that I know of are:
How the SCP protocol works
Ruby net-scp source code
OpenSSH scp source code

how to copy files using ssh under the key-based [pem} configuration

i have a server which is access remote connection only with SSH key auth
i have a key which is stored in my home directory with .pem extension
but when im trying to copy file using the scp command
scp /home/myfilewhichiwannatocopy core#54.32.14.156:/home/core the server asks for password but i don't have it ( btw normal connection using the ssh -i /.ssh/mg.service.pem core#54.32.14.156 fully works) and how to make the scp command for using the key auth?
scp -i /path/to/key.pem somefile.txt user#<machine>:/path
Might I also add, you can consult the man pages https://linux.die.net/man/1/scp

shell script for copying from remote server to local computer using ssh tunneling - scp

I have managed to connect to a remote server through ssh tunneling. No how can I copy files from remote server to my local computer. Considering that I just want to do it from remote server to my local computer.
I dont know how to write this command
"scp file/I/want/to/copy localhost/home/folder"
thanks a lot
Example:
scp username#server:/home/username/file_name /home/local-username/file-name
check this:
http://www.garron.me/linux/scp-linux-mac-command-windows-copy-files-over-ssh.html
scp -r (source)hostname:/(location of the file to be copied)/(file name) (Destination)hostname:/(location of the folder where the file should be copied to)
For example:
scp -r ram.desktop.overflow.com:/home/Desktop/Ram/abcd.txt rajesh.desktop.overflow.com:/home/documents/