LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-30-2013, 07:25 AM   #1
SalientAnimal
LQ Newbie
 
Registered: Nov 2012
Posts: 8

Rep: Reputation: Disabled
Copy From Linux To Windows


Hi All,

I have in the past created cron job that copies files from one linux server to another. I am now looking for a similar soolution, but this time round I need to copy from linux to windows.

I would need to have the script copy the files from a dirctory on the ubuntu machine into a directory for the "current" month on the windows server.

Any help or suggestions please? I'm thinking that the server would have to in someway look at the file to determine the date and then to copy it into the directory for the current month.
 
Old 01-30-2013, 08:37 AM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 126

Rep: Reputation: 28
You have at least 2 options

1. Mount the Windows share on your Linux server and run your script in Linux
2. Run your script from Windows and SFTP to your Linux server

My past experience with Windows scripting is to avoid it whenever possible, so I tend to go for option 1 more than option 2. And if you already have the script written that does what you want in Linux, it shouldn't be very difficult to modify it for this purpose. You could also install an SFTP server on your Windows machine if you don't want to mount the folder directly in Linux.
 
1 members found this post helpful.
Old 01-30-2013, 08:45 AM   #3
SalientAnimal
LQ Newbie
 
Registered: Nov 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
I was looking at the option of installing the SFTP server on the Windows Box, I haven't done this before so just wanted to be sure what the best approach would be.

On the second part of my question, how would I get the script to check the age of the file on the Linux box and then to move it to the relevant folder on the windows box. These folders will be named Jan_2013, Feb_2013, Mar_2013, Apr_2013, etc. Without me having to update the script on the Linux box each month.

Thanks
 
Old 01-30-2013, 09:39 AM   #4
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 126

Rep: Reputation: 28
That depends a little on how you are determining age (created, accessed, modified), and whether you are copying all files or just the new ones. But in general you can use something like this, which looks at the modified date of the file and outputs the Mmm_YYYY based on modified date:

Code:
$ stat -c%Y your_file_here |xargs -I## date -d @## +%h_%Y
$ Jan_2013
So if you had a for loop that ran through your directory hierarchy to look for files, you could use a command similar to above to populate a variable storing which directory each file should be copied to.
 
Old 01-31-2013, 12:15 AM   #5
SalientAnimal
LQ Newbie
 
Registered: Nov 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thanks, I will try that. But it looks like that is what I am looking for.
 
Old 01-31-2013, 12:52 AM   #6
SalientAnimal
LQ Newbie
 
Registered: Nov 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Exclamation

Hi All,

I'm having a problem connecting to the server. I have installed freeSSHd and tested a direct connection through putty. All of these work using the setup username and password. I am connecting through port 21. When trying to sftp username@servername:21 I get access denied on my password.

This is connecting from an Ubuntu Server to a Windows Server.

Any advice?

Thanks.

Last edited by SalientAnimal; 01-31-2013 at 12:55 AM. Reason: Added detail
 
Old 01-31-2013, 02:10 AM   #7
SalientAnimal
LQ Newbie
 
Registered: Nov 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Some update on this, it seems to now be connecting, and then disconnecting due to the following message

ERROR MESSAGE: couldn't canonicalise failure need cwd
DEBUG MODE RESULTS:

OpenSSH_5.4p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to destinationserver [destinationserverip] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type 2
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version WeOnlyDo 2.1.3
debug1: no match: WeOnlyDo 2.1.3
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.4
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Host 'destinationserver' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:52
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: password,publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: password,publickey
debug1: Offering public key: /root/.ssh/id_dsa
debug1: Server accepts key: pkalg ssh-dss blen 433
debug1: read PEM private key done: type DSA
debug1: Authentications that can continue: password,publickey
debug1: Next authentication method: password
fileserver@destinationserver's password:
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending subsystem: sftp
Connected to destinationserver.
Couldn't canonicalise: Failure
Need cwd
 
Old 01-31-2013, 06:42 AM   #8
SalientAnimal
LQ Newbie
 
Registered: Nov 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hey All,

I managed to access the folders. Was a security issue.

I have a few more things I'm stuck on now, but will post it as a new thread.
 
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy from windows to linux acianci Linux - Newbie 5 05-01-2012 10:19 AM
Copy files from Linux onto Windows grob115 Linux - Server 3 11-29-2010 01:08 PM
can't copy from windows to linux(samba) kaibs Linux - Software 2 02-27-2007 01:57 AM
Linux to windows file copy... Wha?Where? Linux - Newbie 1 07-12-2005 10:41 AM
SCP Copy from Linux to Windows? mhague Linux - Newbie 8 11-03-2004 01:56 PM


All times are GMT -5. The time now is 05:43 PM.

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