Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-15-2012, 02:20 AM   #1
Registered: Apr 2011
Posts: 63

Rep: Reputation: 0
Communicating between 2 linux machines / windows-lunux machines

I have situation here.
1. I want to copy files from one linux machine to other programically. I can use scp but how do i pass the password? Is there any other alternative ?

2. i need to copy files from linux to windows. manually i can do that using winscp tool, but how to do using scripts?
Old 03-15-2012, 04:04 AM   #2
Registered: Nov 2011
Location: Iran
Distribution: Debian, CentOS, LFS, CloudLinux
Posts: 377

Rep: Reputation: 8
what programming language are you using?
Old 03-15-2012, 04:57 AM   #3
Satyaveer Arya
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
i need to copy files from linux to windows. manually i can do that using winscp tool, but how to do using scripts?
You can try mounting the Windows drive as a mount point on the Linux machine, using smbfs; you would then be able to use normal Linux scripting and copying tools such as cron and scp/rsync to do the copying.

It could be done with 'smbclient', which acts much like an FTP client to a Windows share. Check out the manpage: man smbclient and look for ways to script it with the -c option, or man expect to drive it.

Here's how I'd probably do it though:

1. Pick which user you're going to be when you sync the files. Log in as this user and type 'id', and get the numeric ID. You will use this ID in step 4
2. Become 'root'
3. mkdir /mnt/sharename
4. Edit your /etc/fstab file and add an entry something like this. Replace the user ID of 500 with your user ID. Replace sharename with your windows share name. Replance WINDOWSHOSTNAME with your host name or IP address. If you don't know the shares, run smbclient -L WINDOWSHOSTNAME.

//WINDOWSHOSTNAME/sharename /mnt/sharename cifs credentials=/root/smblogin,uid=500,noauto,user 0 0
5. Edit /root/smblogin and put the following two lines in it

6. Log in as the user from step 1.

7. Try mounting the share: mount /mnt/sharename
8. If that succeeds, then write a script to do it automatically. Let's call it '':

df | grep -q /mnt/sharename
if test $? -ne 0 ; then
mount /mnt/sharename
cp -r /path/to/dir /mnt/sharename/destination/
9. Use cron to run the script.

a. Type crontab -e
b. Put the following in the file:
# Backup at 2:15 A.M. every day. Run 'man 5 crontab' for help on the time format
15 2 * * * /path/to/


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux guest on Vmware is not communicating to other guest machines Saravana Linux - Virtualization and Cloud 2 10-26-2009 12:14 AM
How do u connect from windows os to linux machines? deostroll Linux - General 6 08-22-2009 09:37 AM
How to browse Windows machines from Linux Fred Affe Linux - Networking 13 02-05-2004 02:39 PM
Windows machines seeing Linux amchjine beeman Linux - Newbie 4 09-29-2003 03:21 PM
communicating two machines lakshman Linux - Networking 1 02-27-2003 02:32 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:48 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration