Step 3.4 Use PuTTYs Tools to Transfer Files from the Windows Command Line

Step 3 4 Use PuTTY s Tools to Transfer Files from the Windows Command Line

Problem: Something is needed to replace the insecure FTP and rcp Windows command line utilities.

Action 3 4 1 Interactively transfer files from the command line with PSFTP

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

The following is an example PSFTP session showing how to connect to remote server server.example.com as user sshuser and transfer files.

Action 3 4 2 Transfer files from the command line with PSCP

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.

Note  

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:

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.

Категории