Problem: Something is needed to replace the insecure FTP and rcp Windows command line utilities.
PSFTP is run from the command line and provides numerous options. To see the options available run PSFTP with the “h option:
C:>psftp -h PuTTY Secure File Transfer (SFTP) client Release 0.53b Usage: psftp [options] user@host Options: -b file use specified batchfile -bc output batchfile commands -be don't stop batchfile processing if errors -v show verbose messages -load sessname Load settings from saved session -l user connect with specified username -P port connect to specified port -pw passw login with specified password -1 -2 force use of particular SSH protocol version -C enable compression -i key private key file for authentication -batch disable all interactive prompts
psftp> help ! run a local Windows command bye finish your SFTP session cd change your remote working directory chmod change file permissions and modes del delete a file dir list contents of a remote directory exit finish your SFTP session get download a file from the server to your local machine help give help lcd change local working directory lpwd print local working directory ls list contents of a remote directory mkdir create a directory on the remote server mv move or rename a file on the remote server open connect to a host put upload a file from your local machine to the server pwd print your remote working directory quit finish your SFTP session reget continue downloading a file ren move or rename a file on the remote server reput continue uploading a file rm delete a file rmdir remove a directory on the remote server
The following is an example PSFTP session showing how to connect to remote server server.example.com as user sshuser and transfer files.
C:> psftp psftp: no hostname specified; use "open host.name" to connect psftp>
where user is the optional user ID you will connect to the remote machine as and hostname is the name or IP address of the host to which you will connect. You can alternatively specify the remote host and user name when invoking PSFTP from the command line.
If you have not connected to this machine previously, you may be asked whether or not you want to cache the host key.
Once the connection to the machine is open, you will be prompted for authentication. Upon successful authentication, the connection to the remote machine will have completed and the transfer of files can begin.
psftp> open email@example.com Using username "sshuser". firstname.lastname@example.org's password: ******** Remote working directory is /home/sshuser psftp>
psftp> lpwd Current local directory is C: psftp> lcd c: emp New local directory is c: emp psftp> lpwd Current local directory is c: emp psftp>
psftp> pwd Remote directory is /home/sshuser psftp> cd /tmp Remote directory is now /tmp psftp>
For those familiar with UNIX, the "ls" command can be used in place of "dir". Use the "help" command to see a full listing of commands available.
psftp> dir Listing directory /tmp drwx------ 2 root root 1024 Jan 9 14:07 . drwxr-xr-x 8 root root 1024 Jan 9 14:06 .. -rw-r--r-- 1 root root 124 Jan 9 14:06 test.c -rw-r--r-- 1 root root 3511 Jan 9 14:06 test.C -rw-r--r-- 1 sshuser sshuser 151 Jan 9 14:07 test.pl psftp>
get remote-filename [ local-filename ]
where remote-filename is the name of the file you wish to download. You can optionally specify a new name for the downloaded file with the local-filename argument:
psftp> get test.pl remote:/tmp/test.pl => local:test.pl psftp>
So, in order to see if a file you wish to upload is present in the current local directory - test.sh in this case - we will use the "!" command with dirtest.sh as its arguments.
psftp> !dir test.sh Volume in drive C has no label. Volume Serial Number is 1234-ABCD Directory of C: emp 07/10/02 03:03p 165 test.sh 1 File(s) 165 bytes 4,577,963,520 bytes free psftp>
put local-filename [ remote-filename ]
where local-filename is the name of the file you wish to upload. You can also optionally specify a new name for the file to be uploaded as with the remote-filename argument.
psftp> put test.sh local:test.sh => remote:/tmp/test.sh psftp> dir Listing directory /tmp drwxrwxrwt 2 root root 1024 Jan 9 14:07 . drwxr-xr-x 8 root root 1024 Jan 9 14:06 .. -rw-r--r-- 1 root root 124 Jan 9 14:06 test.c -rw-r--r-- 1 root root 3511 Jan 9 14:06 test.C -rw-r--r-- 1 sshuser sshuser 151 Jan 9 14:07 test.pl -rw-rw-r-- 1 sshuser sshuser 165 Jan 9 14:37 test.sh psftp>
psftp> bye C:>
A second method to transfer files from a Windows command line prompt is to use PSCP. Unlike PSFTP, PSCP is not interactive and is designed to transfer files "in one shot" and then exit, much like OpenSSH's scp command. PSCP also allows you to specify wildcards within filenames (PSFTP does not). Additionally, PSCP will work with any SSH server as it is not dependent on SSHv2 being present.
PSCP will blindly copy files to the remote server, overwriting any files with the same name , without prompting for verification. Be careful when using PSCP to copy files.
If you wish to prevent PSCP from overwriting any files, remove any write permissions on any file you wish to keep. This can be done on a UNIX system by issuing the following command:
$ chmod --w file
This will prevent PSCP from overwriting the file.
PSCP is run from the command line and has many options, which you can see via the “h option:
C:>pscp -h PuTTY Secure Copy client Release 0.53b Usage: pscp [options] [user@]host:source target pscp [options] source [source...] [user@]host:target pscp [options] -ls user@host:filespec Options: -p preserve file attributes -q quiet, don't show statistics -r copy directories recursively -v show verbose messages -load sessname Load settings from saved session -P port connect to specified port -l user connect with specified username -pw passw login with specified password -1 -2 force use of particular SSH protocol version -C enable compression -i key private key file for authentication -batch disable all interactive prompts -unsafe allow server-side wildcards (DANGEROUS)
Some of the more common options are explained in more detail below:
The following are two examples of utilizing PSCP to exchange files with machine server.example.com as user sshuser .
The syntax for downloading a file from a remote machine is as follows :
pscp user@hostname:remote-filename local-filename
where user is the user ID to which you will connect on the remote machine, hostname is the hostname or IP address of the remote machine, remote-filename is the full path and name of the file on the remote machine to download and local-filename is the full path and name of the downloaded file.
It is not necessary to specify the directory for the remote-filename or target-filename arguments. If the directory is not specified in the remote-filename argument, PSCP assumes the file is in the remote home directory of the user ID that is specified. If the directory is not specified in the local-filename argument, PSCP will download the file into the current directory. However, both arguments are required, so if you do not wish to change the name of the downloaded file and you want to put it into the current local directory, specify "." for the local-filename argument. "." represents the current directory:
C:>pscp email@example.com:test.pl . firstname.lastname@example.org's password: ******** test.pl 0 kB 0.1 kB/s ETA: 00:00:00 100% C:>
The syntax for uploading a file is as follows:
pscp local-filename user@hostname:remote-filename
where user is the user to connect to on the remote machine, hostname is the hostname or IP address of the remote machine, local-filename is the full path and name of the local file to upload and remote-filename is the full path and name of the remote uploaded file. If no directory is specified for the local-filename argument, the current local directory will be used. If no directory is specified for the remote-filename argument, the remote home directory of the user logging in will be used. However, the colon following the hostname must still be present.
C:>pscp test.* email@example.com:/tmp firstname.lastname@example.org's password: test.c 0 kB 0.1 kB/s ETA: 00:00:00 100% test.sh 0 kB 0.2 kB/s ETA: 00:00:00 100% C:>
SECTION I - Obtaining, Compiling and Installing OpenSSH
SECTION II - How to Use OpenSSH Clients for Unix-to-Unix Connectivity
SECTION III - How To Use PuTTY/WinSCP For PC-To-Unix Connectivity
SECTION IV - Using Public Key Authentication
SECTION V - Troubleshooting SSH Connections
SECTION VI - Advanced SSH Topics
Appendix - Sample sshd_config File