Hi,
I am new to this forum, I want to write a script which will transfer files from linux to windows,
on my Linux server ftp is disabled,
Hi,
I am new to this forum, I want to write a script which will transfer files from linux to windows,
on my Linux server ftp is disabled,
For a scriptable, reliable transfer there are two practical paths depending on what the Windows side can run or expose. 's Samba idea is easiest when a writable SMB share is available; 's SCP suggestion is best if you can enable an SSH server on Windows; 's smbclient example is useful for ad-hoc pushes. Below are small, safe workflows you can script and schedule.
Mount the Windows share on Linux (good when SMB is allowed). Create a credentials file (600 perms), mount once and use normal tools (cp/rsync) from scripts:
# /etc/smbcredentials (chmod 600)
username=winuser
password=secret
# mount
sudo mount -t cifs -o credentials=/etc/smbcredentials,vers=3.0,uid=1000,gid=1000 //WINDOWS_HOST/Share /mnt/windows
# then from a script
rsync -av --remove-source-files /path/to/source/ /mnt/windows/ Push via SSH/SCP (good when Windows runs OpenSSH). Use key-based auth to avoid interactive passwords, then a tiny push script:
# create key on Linux
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ''
# copy pub key to Windows user's authorized_keys (or use ssh-copy-id)
# push script: /usr/local/bin/push_files.sh
for f in /path/to/outgoing/*; do
scp "$f" user@windows-host:/path/on/windows/ && rm -f "$f"
done Troubleshooting and cautions: test the transfer manually before cron, avoid putting plaintext passwords on command lines (use credential files), ensure firewalls allow the service (SMB: 445/139, SSH: 22), and set correct Windows ACLs for the target share. For large or flaky transfers prefer rsync (resume, checksum) or implement logging and retries in your script.
Jump to Post— linux 107A script? Why not just use Samba?
Jump to Post— BillBrown 0Do you mean you want to transfer files from like hdb# (Linux /) to hdb# (/mnt/windows) or to a different machine entirely?
A script? Why not just use Samba?
Do you mean you want to transfer files from like hdb# (Linux /) to hdb# (/mnt/windows) or to a different machine entirely?
Well judging from his saying that his ftp server is disabled, I'd say two different machines.
I use scp which is a secure copy over SSH. First get SSH installed and running on the Linux machine.
On the Windows machine install WinSCP
once thats connected it's almost as simple as drag and drop to transfer files using a a nice split screen for files.
But a script would be a little more challenging...off hand I know of a way with FTP but then you'd have to set up the Windows machine as a FTP server. I think we need more details on what you are trying to do, like does the Windows machine have any open shares or anything that we can use?
Hi,
I am new to this forum, I want to write a script which will transfer files from linux to windows,on my Linux server ftp is disabled,
On your Linux machine create a script that will use smbclient to transfer your file which might look something like this:
======================= CAUTION : UNTESTED!!! =====================
I just wrote this on the fly...
====================== USE AT YOUR OWN RISK!!! ====================
#!/bin/bash
#
# cp2win
# Transfer a file to a windows machine using smbclient
# Script by hardwyrd (c) 2008
#
# Syntax:
# cp2win switch host-folder file remote-username remote-password
#
# Example:
# cp2win nologin \\\\myserver\myshare myfile.txt
# cp2win \\\\myserver\myshare myfile.txt myuser mypassword
#
# switch:
# nologin - turns on using login credential
#
# host-folder: must be in the format \\\\machine\folder
case $1 in
nologin )
smbclient $2 -c "put $3"
;;
* )
smbclient $1 -U $3%$4 -c "put $2"
;;
esac
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.