Thursday, September 19, 2013

How to Transfer Files Using PuTTY - PSCP


PuTTY is the CIT-recommended application for secure file transfer using SCP between Windows clients and Windows or Unix servers.
PuTTY is available from PuTTY.org.

Install PuTTY and Set up a Server Connection

PuTTY is the recommended SCP client for Windows client and Unix server file transfers at Cornell. PuTTY is available from PuTTY.org.
  1. Download the pscp.exe file from PuTTy.org. Click the file name and save it to your computer.
    If you want a PuTTY shell program, download and install putty.exe as well.
You are now connected to the server and can begin transferring files.

Transfer Files Using PuTTY

  1. Open a Windows command line window. On the Start menu, click Run.

    filewindowsstart
  2. In the Open box, type cmd, and then click OK.

    filewindowscmd


Add putty scp client( pscp.exe) and (putty.exe) path to windows Environment Variable

MS Windows uses a concept of paths to go searching for where programs are located on your hardware. When using the DOS box, the operating system has no context about where your programs are located on the hard drive. When using the GUI, the information about where the program is located, is contained in the Shortcut that you are clicking on.
You could start PuTTY by typing something like this:
PuTTY-cli-10.jpg
but that is too much typing for me.
We can tell Windows that the directory where the PuTTY program is and to look in there for the program as needed.

To the Control Panel System tab then

In the Control Panel, System Properties, select the Environment Variables button at the bottom:
PuTTY-cli-11.jpg
and then select Path in the System Variables section, and press the Edit button.
PuTTY-cli-12.jpg
PuTTY-cli-13.jpg
and it will look like this ( you need to be a little bit careful here not to delete the content, if you think you have mis-types then just press escape and start over), on the end of the line enter the following text exactly (including the semi colon):
;C:Program FilesPuTTY
PuTTY-cli-15.jpg
This set the path variables to include the PuTTY program directory in the search path. You only have to do this once. Windows will set the the Environment Variable permanently from now on.
You will need to logout at this point, or restart. The Path Variables are only read once at boot time.
When you come back, open the DOS box again (Ctrl-Escape, R, cmd, Enter – just to remind you), and type path to confirm the variables are in place.
PuTTY-cli-17.jpg



  1. At the Windows command prompt, enter:
    pscp source_file_name userid@server_name:/path/destination_file_name.

    For example:
    c:\>pscp june06extract wrhse@warehouse.cit.cornell.edu:/mydata/june06extract.

  2. When prompted, enter your password for the server.
Note: Complete documentation for PuTTY is on the PuTTY.org site.


Obtaining and Using PSCP

PSCP is a freeware SCP (Secure CoPy) program for the Windows command line processor. You can use this program instead of FTP for copying files to or from the Unix servers at the NBER offices. FTP is not allowed from clients outside nber.org to servers inside the firewall because FTP leaves passwords in plain-text and vulnerable to eavesdropping. PSCP should work with any host supporting SSH.

Details:

  • Download PSCP here.
  • Save pscp.exe somewhere on your hard drive. C:\windows\ is a good location in the default execution path.
  • The command line syntax is:

    • pscp [options] [user@]host:source target
    • pscp [options] source [source...] [user@]host:target

      Options:
      -p preserve file attributes
      -q quiet, don't show statistics
      -r copy directories recursively
      -v show verbose messages
      -P port connect to specified port
      -pw passw login with specified password

      source or target may be a pathname or a ~userid/filename (on the Unix side). You will be prompted for the password of `user'. This is an old-fashioned command line program - you need to open a DOS window to run it.
Copying files from your UNIX host to your Windows PC.

  • In order to copy a file from your UNIX host to your Windows PC your command line would look like this:

    • pscp username@yourhost:file.foo c:\temp\file.foo
    • This command line copies "file.foo" located in your home directory on your UNIX host to the temp directory on your C:\ drive.
Copying files from your Windows PC to our UNIX host.

  • In order to copy a file from your Windows PC to your our Unix host your command line would look like this:

    • pscp -v c:\"my documents"\file.foo username@nber.org:file.foo

    • This command line copies "file.foo" located in the "my documents" directory on your C:\ drive to your home directory on our Unix cluster.
    • Remember: Backslashes (\) for your DOS and Windows files and forward slashes (/) for your UNIX files. 

Connecting to a Samba Share (File sharing Linux vs Windows)

19.3.1. Command Line

To query the network for Samba servers, use the findsmb command. For each server found, it displays its IP address, NetBIOS name, workgroup name, operating system, and SMB server version.
To connect to a Samba share from a shell prompt, type the following command:

smbclient //<hostname>/<sharename> -U <username> 
 
root@itadmin-AcerPower-Series:/# clear

root@itadmin-AcerPower-Series:/# smbclient //192.168.2.100/shared -Uitadmin
Enter itadmin's password: 
Domain=[CHNSRV] OS=[Windows Server 2003 3790 Service Pack 1] Server=[Windows Server 2003 5.2]
smb: \> ls
  .                                  DR        0  Thu Sep 19 11:34:36 2013
  ..                                 DR        0  Thu Sep 19 11:34:36 2013
  .DS_Store                          AH    24580  Tue Sep 17 12:22:12 2013
  admin                               D        0  Wed Aug 14 20:11:47 2013
  kumar                               D        0  Thu Sep 12 17:27:38 2013
  shiva                               D        0  Wed Sep 18 08:47:51 2013
  siva                                D        0  Wed Sep  4 18:44:45 2013
  
  51203 blocks of size 2097152. 7692 blocks available
smb: \>






(or) Suppose your Linux machine user name is same as Network windows server user name, Here no
need -U itadmin(username)

itadmin@itadmin-AcerPower-Series:/$ smbclient //192.168.2.100/shared
Enter itadmin's password: 
Domain=[CHNSRV] OS=[Windows Server 2003 3790 Service Pack 1] Server=[Windows Server 2003 5.2]
smb: \> ls
  .                                  DR        0  Thu Sep 19 11:34:36 2013
  ..                                 DR        0  Thu Sep 19 11:34:36 2013
  .DS_Store                          AH    24580  Tue Sep 17 12:22:12 2013
  kumar                               D        0  Thu Sep 12 17:27:38 2013 
  shiva                               D        0  Wed Sep 18 08:47:51 2013
  siva                                D        0  Wed Sep  4 18:44:45 2013
  Sundar                              D        0  Wed Sep 18 17:17:51 2013
  51203 blocks of size 2097152. 7692 blocks available
smb: \> 

Replace <hostname> with the hostname or IP address of the Samba server you want to connect to, <sharename> with the name of the shared directory you want to browse, and <username> with the Samba username for the system. Enter the correct password or press Enter if no password is required for the user.
If you see the smb:\> prompt, you have successfully logged in. Once you are logged in, type help for a list of commands. If you wish to browse the contents of your home directory, replace sharename with your username. If the -U switch is not used, the username of the current user is passed to the Samba server.
To exit smbclient, type exit at the smb:\> prompt.

Copy from widows shared file to Linux machine through Linux Terminal using smbclient:

smb: \siva\> get email1.png /home/itadmin/Documents/email1.png
getting file \siva\email1.png of size 292535 as /home/itadmin/Documents/email1.png (10202.8 KiloBytes/sec) (average 7935.5 KiloBytes/sec)
smb: \siva\> 


Copy from Linux machine file to Windows shared folder through Linux Terminal using smbclient:


smb: \siva\> put /home/itadmin/Documents/siva1.png siva1.pngputting file /home/itadmin/Documents/siva1.png as \siva\siva1.png (8162.2 kb/s) (average 8527.7 kb/s)
smb: \siva\> ls
 
.                                   D        0  Thu Sep 19 15:04:06 2013
  ..                                  D        0  Thu Sep 19 15:04:06 2013
   comics                              D        0  Wed Jul 10 16:49:33 2013
  Copy of icon_helpdesk.gif           A     1657  Wed Jul  3 13:45:49 2013
  Copy of livechat.png                A    17260  Wed Jul  3 16:37:07 2013
  Elvis-Testing.avep                  A  6991460  Wed Jul 10 13:01:52 2013
  Elvis-Testing.avep-Pages.zave       A  2238570  Wed Jul 10 14:19:06 2013
  Elvis-Testing.avep-Pages.zavem      A      341  Wed Jul 10 14:19:05 2013
  email1.png                          A   292535  Mon Jul  1 12:21:58 2013
  email2.png                          A     8622  Mon Jul  1 12:30:19 2013
  email35.png                         A     7618  Mon Jul  1 12:30:35 2013
  event.png                           A     1809  Wed Sep  4 18:44:07 2013
  forum.png                           A     1668  Sat Jun 29 15:11:03 2013
  icon_helpdesk.gif                   A     1657  Wed Jul  3 13:45:49 2013
  icon_helpdesk.png                   A     4505  Wed Jul  3 13:51:57 2013
  icon_helpdesk40.png                 A     4667  Wed Jul  3 13:52:16 2013
  KalleAnka&Co 1.0.2.ipa              A 32092113  Wed Jul 10 16:23:07 2013
  live100.png                         A     7373  Thu Jul  4 13:07:07 2013
  live150.png                         A     9953  Thu Jul  4 13:06:55 2013
  live80.png                          A     6503  Thu Jul  4 13:07:17 2013
  livechat.png                        A    17260  Wed Jul  3 16:37:07 2013
  logo.gif                            A     1843  Fri Aug 16 11:26:57 2013
  logo.png                            A     7289  Thu Aug  8 18:37:02 2013
  logos.gif                           A     1780  Fri Aug 16 11:33:40 2013
  magik_pinstyle_3                    D        0  Wed Jul 24 18:48:37 2013
  nforum.png                          A     5048  Sat Jun 29 15:44:46 2013
  photo                               D        0  Mon Aug 19 13:51:38 2013
  ricon.png                           A     1959  Sat Jun 29 15:32:37 2013
  scpsmb                              D        0  Wed Sep  4 18:45:39 2013
  sforum.png                          A     1668  Sat Jun 29 15:11:08 2013
  siva2.png                           A   292535  Thu Sep 19 15:03:04 2013
  siva1.png                           A   292535  Thu Sep 19 15:04:06 2013
  slide                               D        0  Wed Jul 31 16:07:19 2013
  sundarnew.png                       A     6925  Fri Aug  9 11:05:45 2013
  Thumbs.db                         AHS    82432  Mon Aug 19 13:51:40 2013
  webim                               D        0  Fri Aug  2 11:47:46 2013

        51203 blocks of size 2097152. 7692 blocks available

 



19.3.2. Mounting the Share

Sometimes it is useful to mount a Samba share to a directory so that the files in the directory can be treated as if they are part of the local file system.
To mount a Samba share to a directory, create create a directory to mount it to (if it does not already exist), and execute the following command as root:
 
 
mount -t cifs -o <username>,<password> //<servername>/<sharename> /mnt/point/


This command mounts <sharename> from <servername> in the local directory /mnt/point/. For more information about mounting a samba share, refer to man mount.cifs.