LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-09-2017, 01:41 PM   #16
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,614
Blog Entries: 3

Rep: Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859

Quote:
Originally Posted by trickydba View Post
@Turbocapitalist.....Im sorry, your code seems a little confusing

And no password is needed, keys already installed
The first example is just copy/paste from the terminal. There is a Here Document showing the lines you added. You can use gedit, nano, vi, or any editor instead to create the file with the SFTP commands.
 
Old 01-09-2017, 01:43 PM   #17
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
If you have keys that work for sshd they should work for both scp and sftp.

If so your one liner would be similar to what schneidz posted.
scp -p <pathtof/><localfile on linux> <windowsserver>:<pathto/><remotefile

You can leave off remotefile if you want it to be the same name as the localfile.
 
1 members found this post helpful.
Old 01-09-2017, 02:09 PM   #18
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
A windows command-line pscp is included with putty. I've used in batch scripts it to automate scp from linux to windows.
 
1 members found this post helpful.
Old 01-09-2017, 02:20 PM   #19
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@Turbocapitalist..........I'm sorry, still a little confused. maybe I should show exactly what I need to be done in the script:

1. sftp username@hostname ----- no password needed, keys are used
2. cd MOVEFILEHERE ----- this is where the file will be written to
3. lchdir /dir1/dir2/dir3/ ----- this is the local directory where the file exists
4. put file.xlsx ----- to actually move the file
 
Old 01-09-2017, 02:24 PM   #20
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@Mensawater.......I tried that and it didn't work. It gave the error:

exec request failed on channel 0
lost connection
 
Old 01-09-2017, 02:24 PM   #21
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,614
Blog Entries: 3

Rep: Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859
That's what I showed in #10 above. Please try some experiments with -b

Code:
echo -e "cd MOVEFILEHERE\nlchdir /dir1/dir2/dir3/\nput file.xlsx\n" | sftp -b - username@hostname
Or you can make a file with those three SFTP commands (2, 3, and 4) and use the file name instead of a dash.
 
1 members found this post helpful.
Old 01-09-2017, 02:37 PM   #22
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@Mensawater... Windows server only configured for sftp connections
 
Old 01-09-2017, 02:42 PM   #23
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@Turbocapitalist.............PERFECT!!!! That works!!! Here's the suggested code:

echo -e "cd MOVEFILEHERE\nlchdir /dir1/dir2/dir3/\nput file.xlsx\n" | sftp -b - username@hostname

Thank you
 
1 members found this post helpful.
Old 01-10-2017, 12:49 AM   #24
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,614
Blog Entries: 3

Rep: Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859
Hmm. You're welcome. For my edification, what was confusing about how it was written in #10?
 
Old 01-10-2017, 09:05 AM   #25
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@Turbocapitalist.......Well I'm sort of a newbie. Which is why I always be in here! Also I thought when concerning the keys it's all done in the background and doesn't need to be mentioned in a script. I can confirm I can do this MANUALLY using sftp so the keys are configured right. I just want to move the file from linux to windows.

Last edited by trickydba; 01-10-2017 at 09:43 AM.
 
Old 01-10-2017, 12:22 PM   #26
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,614
Blog Entries: 3

Rep: Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859Reputation: 2859
Ok. Yeah if you have an agent (ssh-agent) running then it goes more or less automatically. Most if not all desktop environments start one for you these days. But when you start to have more than about six accounts to worry about, you start to have to point the SFTP client at a specific key. So I included that with the -i option.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot transfer files between windows and ubuntu - SFTP host disconnected and connect ns_chrys Linux - Networking 7 09-29-2013 10:48 AM
[SOLVED] Transfer files in sftp xeon123 Linux - Networking 7 12-17-2010 11:04 AM
SFTP throwing "End of file" when doing SFTP transfer in perl exceed1 Programming 5 03-06-2010 01:34 PM
Can transfer only 2MB using sftp nIMBVS Debian 1 11-26-2005 03:26 PM
sftp: how to transfer the whole directory? kpachopoulos Linux - General 1 11-06-2005 08:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:53 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration