Automate scp file transfer using a shell script

Instead of hardcoding password in a shell script, use SSH keys, its easier and secure. $ scp -i ~/.ssh/id_rsa *.derp devops@myserver.org:/path/to/target/directory/ assuming your private key is at ~/.ssh/id_rsa and the files you want to send can be filtered with *.derp To generate a public / private key pair : $ ssh-keygen -t rsa The above … Read more

How to scp with a second remote host

I don’t know of any way to copy the file directly in one single command, but if you can concede to running an SSH instance in the background to just keep a port forwarding tunnel open, then you could copy the file in one command. Like this: # First, open the tunnel ssh -L 1234:remote2:22 … Read more

recursively use scp but excluding some folders

Although scp supports recursive directory copying with the -r option, it does not support filtering of the files. There are several ways to accomplish your task, but I would probably rely on find, xargs, tar, and ssh instead of scp. find . -type d -wholename ‘*bench*/image’ \ | xargs tar cf – \ | ssh … Read more

How to filter files when using scp to copy dir recursively?

I’d probably recommend using something like rsync for this due to its include and exclude flags, e.g:- rsync -rav -e ssh –include ‘*/’ –include=”*.class” –exclude=”*” \ server:/usr/some/unknown/number/of/sub/folders/ \ /usr/project/backup/some/unknown/number/of/sub/folders/ Some other useful flags: -r for recursive -a for archive (mostly all files) -v for verbose output -e to specify ssh instead of the default (which … Read more

Single line sftp from terminal

Update Sep 2017 – tl;dr Download a single file from a remote ftp server to your machine: sftp {user}@{host}:{remoteFileName} {localFileName} Upload a single file from your machine to a remote ftp server: sftp {user}@{host}:{remote_dir} <<< $’put {local_file_path}’ Original answer: Ok, so I feel a little dumb. But I figured it out. I almost had it … Read more

How to copy a file to a remote server in Python using SCP or SSH?

To do this in Python (i.e. not wrapping scp through subprocess.Popen or similar) with the Paramiko library, you would do something like this: import os import paramiko ssh = paramiko.SSHClient() ssh.load_host_keys(os.path.expanduser(os.path.join(“~”, “.ssh”, “known_hosts”))) ssh.connect(server, username=username, password=password) sftp = ssh.open_sftp() sftp.put(localpath, remotepath) sftp.close() ssh.close() (You would probably want to deal with unknown hosts, errors, creating any … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)