ftp upload in one command

Posted by caike on March 04, 2010

As part of a backup routine, I had to upload a file to an ftp server. It actually took me some time to figure out how to do this with one command, so I thought I’d post it here:

curl -sS -T ${FILE_PATH}/${FILE_NAME} --ftp-pasv \
ftp://${FTP_USER}:${FTP_PWD}@${FTP_URL}/${FILE_NAME}

This example is uploading the file to the ftp server using silent mode (-s) and showing errors when they occur (-S), while connecting to the server in passive mode (–ftp-pasv).

Remote Pair Programming with Screen 5

Posted by caike on May 15, 2009

If you have ever felt the need to do remote pair-programming and didn’t know of any tools around to help you do that, here is a quick tip using Screen.

Screen is a window-manager that makes it possible to share a single session among users logged onto the same machine, allowing them to interact with each other in real time.

This assumes that you:

a) have access to at least one Linux/Unix box with Screen and SSH enabled.
b) are comfortable working with a command line editor (vi, vim, emacs, etc).

For this example we will be using Screen 4, which is probably already bundled with your favorite Linux distro or OS X. If you happen not to have it, apt-get/yum/port/whatever to install it.

In order to have multiusers on one Screen session, some file permissions need to be changed. Screen needs to be able to be run as root and the /var/run/screen folder needs some executing permission.

sudo chmod +s /usr/bin/screen
sudo chmod 775 /var/run/screen

Now the first user - let’s call it foo - can log in to the Linux box via SSH and start a Screen session named pairprog.

[foo@linuxbox ~]$ screen -S pairprog

The user foo, now on Screen, needs to turn on multiuser mode and grant access to his friend, the user named bar.

^A :multiuser on
^A :acladd bar

(^A means ‘control + A’, which is the way commands are passed to Screen)

Now it is time for the user bar to log in to the same Linux box and join foo’s Screen session.

[bar@linuxbox ~]$ screen -x foo/pairprog

Now both users should see each others’ activities.

Fire up your favorite command line editor, start a voice chat (using Skype or something) and you’re good to go in no time!

Update! It is worth mentioning that the user foo actually shared everything. This might cause security implications, since the guest user (bar) will act as the host user. You can give the host user read-only permission by:

^A :aclchg bar -w "#"

Probably the best way to use Screen for session sharing would be to create a new “public” user and use it as the host for the session. Place all the files under this public users’ directories or other public directories.

Thanks for pointing it out, Pigor!