-   Linux - General (
-   -   Copy From Linux To Windows (

SalientAnimal 01-30-2013 08:25 AM

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.

thesnow 01-30-2013 09:37 AM

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.

SalientAnimal 01-30-2013 09:45 AM

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.


thesnow 01-30-2013 10:39 AM

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:


$ 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.

SalientAnimal 01-31-2013 01:15 AM

Thanks, I will try that. But it looks like that is what I am looking for.

SalientAnimal 01-31-2013 01:52 AM

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?


SalientAnimal 01-31-2013 03:10 AM

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

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_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

SalientAnimal 01-31-2013 07:42 AM

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.

All times are GMT -5. The time now is 06:18 PM.