[SOLVED] Using SFTP to transfer from linux to Windows
Linux - NewbieThis 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!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Well first you need an SFTP server on your Windows box with the necessary firewall exceptions added. After that, you need an sftp uploading tool on your Linux box since the built-in sftp won't let you do it all in one line (I don't think). There are many options, my preference is "lftp".
To initiate the sftp from the Linux side to the Windows side you'd have to setup an sshd to listen for sftp connections on the Windows side first. You can do this with Cygwin. Cygwin can be found at: https://www.cygwin.com/
There are many articles on how to configure sshd for sftp in Cygwin - just do a web search.
To initiate the sftp from the Windows side to the Linux side there are various tools you can use including WinSCP. WinSCP can be found at: https://winscp.net/eng/download.php
WinSCP uses an explorer style menu to drag files from one system to the other. There is also a WinSCP console you can run that gives you a command line interface to run sftp commands manually.
I'd make the opposite assumption from the previous two posts. Since you wish to transfer a file from linux to Windows using SFTP, I'd say put the OpenSSH server on the Linux box. It will be many thousands of times easier. Then you'll still have to figure out a client for the Windows side of things, but at least the server will be done the easy way.
From the OP's previous threads there is a ssh server running on Windows and can use scp and smbclient to transfer files. What are you trying to accomplish with sftp?
Either way, you have to have the key set up so that it is in the agent if it has a passphrase (recommended) or without a passphrase (not recommended). Because batch mode only works when there is no interactive session.
Last edited by Turbocapitalist; 01-09-2017 at 02:25 PM.
@Turbocapitalist............I was kinda hoping to get a one-liner that would handle moving a file from linux to windows. The destination server does not need a password
Either way, you have to have the key set up so that it is in the agent if it has a passphrase (recommended) or without a passphrase (not recommended). Because batch mode only works when there is no interactive session.
ssh keys are definitely the most secure way to go and should always be what you try to get in place for automated processes.
However, there is a utility that allows you to send the password, called sshpass. Obviously this has a security risk as it requires you to store your password in clear text somewhere to be passed. But it does work well if you absolutely can't use keys for some reason and has simple syntax:
shpass -p <password> sftp <target server name or IP>
If you're using RHEL or CentOS you can find the package in Fedora's EPEL.
Both examples are from any non-Windows OS with the usual OpenSSH SFTP client to whatever SFTP server you have, as long as it follows the standards.
The stdin example is one line. The backslash is not necessary and is added for readability. The file-based example is also one line, but does need the file filled with SFTP commands. Both work as long as you can use keys for authentication. If you are using expect instead of keys then you are probably SOL.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.