Uploading Files to EC2 with Blink

1 minute read

The Blink shell is a powerful ssh/mosh iOS app for developers. But how do you upload files from your device to your remote machine? Blink also has a local shell that lets you manage the files in its sandbox and the scp and sftp commands to transfer those to a remote machine.

iCloud Folder

Blink folder in iCloud Blink has an iCloud folder, which allows you to save files from anywhere you have access to your iCloud storage. This could be your Mac, an iOS device, or another device with a web browser. The easiest way to get files into the Blink sandbox is to use this folder.

Watch out! The iCloud folder doesn’t appear in the Files app (or iCloud) until a file is created in it. The local shell conveniently has the touch command that can be used to do exactly that.

# Create a file in the iCloud folder to force its creation
blink> touch iCloud/file
blink> rm iCloud/file

Other Folders

If you don’t use iCloud or you already have files in another service or folder, you can link that folder to the Blink sandbox. So long as the folder is available in the Files app, you can use the link-files command in the local shell to gain access to it from Blink. When you’re done working with the folder, use the unlink command to remove it from the local shell.

Transfering Files using scp

Blink has implemented scp using curl. It’s easiest to use with a saved host because it will use the saved credentials for that host.

# View the contents of the iCloud folder
blink> ls iCloud/
diagram.png

# Copy the file to your saved host (here, named ec2)
blink> scp -q iCloud/diagram.png ec2:~/diagram.png

# View the file on the remote machine
blink> ssh ec2
ec2$ ls
diagram.png

Watch out! If you’re using a PEM file from the AWS console, you may have to connect via ssh2 before scp will work. This is because scp is implemented on top of curl and the key won’t automatically work.

blink> # scp fails with a curl error
blink> scp -q iCloud/diagram.png ec2:~/
curl: (51) SSL peer certificate or SSH remote key was not OK

blink> # Fix it by connecting with ssh2
blink> ssh2 ec2
ec2$ logout

blink> # Retry and it succeeds