============================== File transfer between machines ============================== -IAN! idallen@idallen.ca This file explains how to move files between Unix machines and between Unix and other machines (e.g. to your home machine or to a machine in an Access Lab). MS Windows users may want to skip to the later sections dealing with the lack of secure file transfer programs under Windows (and what to do). Contents: * SCP and SFTP - Secure Copy Program, Secure FTP * FTP - File Transfer Protocol * Just use EMail for text files * Microsoft Windows Users - Using PSCP on Windows - Using PSFTP on Windows - Printing Unix Text Files on Windows Note: You cannot use the insecure FTP program to connect *to* the Course Linux Server from a remote machine; you can only connect using SSH (and the companion programs SCP and SFTP). If you are already logged in to the Course Linux Server (using SSH), you can sometimes use the "ftp" or "lftp" commands on the server to connect *out* to other remote machines (e.g. to ACADUNIX), if those other machines accept insecure FTP connections. (If you set up your home computer with an FTP server [DANGER], you can use the "ftp" command on the Course Linux Server to connect to your home machine.) ---------------------------------------------- SCP and SFTP - Secure Copy Program, Secure FTP ---------------------------------------------- The SCP and SFTP programs should be used to transfer files between machines when a userid/password is required. Both these programs use the underlying SSH (Secure SHell) protocol that encrypts both your password and the data being transferred. Using SCP (from a Unix command line): 1. Copy a file from a remote machine to the local machine's current directory: $ scp -p userid@host.name:remote_file local_file The "userid@" part contains your login userid on "host.name". You can leave off "userid@" if your remote userid is the same as your userid on the local machine. (You will be prompted to enter your password for the remote machine.) The "remote_file" may be an absolute pathname (on "host.name"), or it may be a pathname relative to your home directory (on "host.name"). The "-p" option preserves the modify time of the transferred file. Examples: $ scp -p alleni99@acadunix.algonquincollege.com:dodo.txt happy.txt $ scp -p acadunix.algonquincollege.com:/tmp/foo mydir/bar 2. Copy a file from the local machine's current directory to a remote machine: Just reverse the order of the arguments to SCP: $ scp -p local_file userid@host.name:remote_file $ scp -p happy.txt alleni99@acadunix.algonquincollege.com:dodo.txt $ scp -p mydir/foo acadunix.algonquincollege.com:/tmp/bar You will be prompted to enter your password for the remote machine. You can leave off "userid@" if your userids match on the two machines. Using SFTP: The SFTP program is a cover for SSH and SCP that makes things look like you are using the insecure FTP program; however, the actual connection and transfer is done using the secure SSH protocol: $ sftp alleni99@acadunix.algonquincollege.com Connecting to acadunix.algonquincollege.com... alleni99@acadunix.algonquincollege.com's password: sftp> help [... output similar to using FTP ...] sftp> quit If you are familiar with FTP (see below), SFTP will operate much the same way. As with FTP, you can list the contents of remote directories and transfer files both ways (using "put" and "get") on the same connection. ---------------------------- FTP - File Transfer Protocol ---------------------------- The traditional way to move files between machines is the "FTP" (File Transfer Protocol) program. FTP is an insecure form of file transfer; because, any password you type into FTP is visible across the network. Don't use FTP for transfer between machines requring userids and passwords over an insecure network (e.g. the Internet). Many Internet sites support a form of "anonymous" FTP that lets you connect to a site without requring a password, using the special FTP userid "anonymous" or "ftp". Since it requires no password, this form of FTP is safe to use over the Internet. It is how software is often provided for download to Unix/Linux users. FTP is a "subsystem" kind of program with its own set of subcommands. Once inside the FTP program, your prompt becomes "ftp>". Inside FTP, the "help" command will list the possible commands available, and "help commandname" will give you a bit more help on the given command name. The Unix manual page for FTP ("man ftp") explains the individual FTP subcommands in much better detail. Do not confuse Unix commands with FTP subcommands. Pay attention to which program is prompting you for input. To quit FTP, type "quit". The command-line FTP program is also available under Windows. (You may need to install FTP from the Windows CDROM.) The range of FTP commands is slightly different; but, the basic commands (ls, cd, get, put) are the same as for Unix. (You can run command-line FTP from a DOS window or using the "Run" dialog box.) Remember: FTP is not secure. FTP will not transfer entire directories; it may only be used to transfer files one at a time. (There are ways to get FTP to fetch multiple files at once; but, the files must all be in the same directory; you can't fetch multiple directories. See the help for the "mget" FTP subcommand.) Here is an example FTP session to a public FTP server: $ ftp ftp.gnu.org Connected to ftp.gnu.org. 220 GNU FTP server ready. 530 Please login with USER and PASS. Name (ftp.gnu.org:idallen): anonymous # NOTE: special userid used 230 Login successful. # NOTE: no password needed! Remote system type is UNIX. Using binary mode to transfer files. ftp> help [... many lines of FTP commands show here ...] ftp> help ls ls list contents of remote directory ftp> help get get receive file ftp> help cd cd change remote working directory ftp> ls 150 Here comes the directory listing. [... many files show here ...] ftp> cd gnu ftp> ls 150 Here comes the directory listing. [... many files show here ...] ftp> cd chess ftp> ls 150 Here comes the directory listing. [... many files show here ...] ftp> get README.gnuchess local: README.gnuchess remote: README.gnuchess 150 Opening BINARY mode data connection for README.gnuchess (89 bytes). 226 File send OK. 89 bytes received in 0.0066 seconds (13 Kbytes/s) ftp> quit 221 Goodbye. $ ls -l README.gnuchess -rw-r--r-- 1 idallen idallen 89 Oct 2 00:49 README.gnuchess ----------------------------- Just use EMail for text files ----------------------------- If the file you want to take home from Unix is a text file, you can usually EMail it to yourself using the Unix "mail" program with standard input redirected to come from the file you want: $ mail alleni99@algonquincollege.com <.bashrc $ mail me@hotmail.com <.bashrc You can only send text files this way, and you can only send one file per mail message using file input redirection (unless you concatenate many files together first). See "man mail" for further details. ----------------------- Microsoft Windows Users ----------------------- MS Windows has a command-line version of FTP available from a DOS prompt or in a DOS window. You cannot use FTP to connect to the Course Linux Server; you must use SCP or SFTP. MS Windows does not ship with SCP or SFTP, even though versions exist that are open source and free software. You can buy expensive commercial versions of SSH/SCP/SFTP for Windows from various vendors; or, you can download and install the free PuTTY program suite that contains programs that work like SSH, SCP, and SFTP. If you download and install the full PuTTY program suite under Windows (PuTTY comes with an executable auto-installer that will do this for you), you will find the programs PSCP and PSFTP under the installation directory (usually under C:\Program Files\PuTTY). Start up a DOS command prompt, change to this directory, and run the commands you need to copy files to/from other systems (see below for examples of how to do this). Note that the line end character in text files is not the same between Unix and Windows. A text file written on Unix contains only linefeed (LF, "\n") characters at the ends of lines; Windows expects lines in text files to end in both a carriage-return (CR, "\r") *and* a linefeed character. This may result in "staircasing" text if you send a Unix text file to a Windows printer from some programs (e.g. Notepad). Print a small sample first, and try using "Write" or "Wordpad" instead of "Notepad". Using PSCP on Windows --------------------- C:\> cd "C:\Program Files\PuTTY" C:\Program Files\PuTTY> pscp -h # -h gives a short help listing ...short help listing displays here... C:\Program Files\PuTTY> pscp -P 2330 -l alleni99 \ dat2330.idallen.ca:.bashrc foo.txt ...you may be asked to accept the host key here (say yes)... alleni99@dat2330.idallen.ca's password: ...file transfers ".bashrc" to "foo.txt" in the current directory... Using PSFTP on Windows ---------------------- C:\> cd "C:\Program Files\PuTTY" C:\Program Files\PuTTY> psftp -h # -h gives a short help listing ...short help listing displays here... C:\Program Files\PuTTY> psftp -P 2330 -l alleni99 dat2330.idallen.ca ...you may be asked to accept the host key here (say yes)... alleni99@dat2330.idallen.ca's password: Remote working directory is /home/alleni99 psftp> help ...short help listing displays here... psftp> ls ...listing of directory displays here... psftp> get .bashrc foo.txt remote:/home/alleni99.bashrc => local:foo.txt psftp> quit ...file "foo.txt" is now in the current directory... Printing Unix Text Files on Windows ----------------------------------- Remember that text files from Unix may not print properly on Windows due to the incompatible line end characters. Notepad does not handle Unix text files well; try "Write" or "Wordpad" instead. Adjust the font size smaller so that at least 80-columns fit on your printed page. The standard size of a Unix 8.5x11 inch printed page is 6-lines per inch and 10 characters per inch - 66 lines by 85 columns. Man pages and other text outputs are often formatted to fit this size. Select Courier font and adjust the font size to fit this page size.