How to send multiple commands to sftp using one line
The following command sends one command to sftp using one line:
sftp -o PasswordAuthentication=no user@host" <<<"lcd /home"
How to send multiple lines to sftp using one line. Is there a way to insert carriage returns or something to achieve this, for example:
sftp -o PasswordAuthentication=no user@host" <<<"lcd /homen cd /myhomen get file"
The idea is to NOT use the sftp -b option where an external file listing commands is loaded.
scripting sftp
add a comment |
The following command sends one command to sftp using one line:
sftp -o PasswordAuthentication=no user@host" <<<"lcd /home"
How to send multiple lines to sftp using one line. Is there a way to insert carriage returns or something to achieve this, for example:
sftp -o PasswordAuthentication=no user@host" <<<"lcd /homen cd /myhomen get file"
The idea is to NOT use the sftp -b option where an external file listing commands is loaded.
scripting sftp
add a comment |
The following command sends one command to sftp using one line:
sftp -o PasswordAuthentication=no user@host" <<<"lcd /home"
How to send multiple lines to sftp using one line. Is there a way to insert carriage returns or something to achieve this, for example:
sftp -o PasswordAuthentication=no user@host" <<<"lcd /homen cd /myhomen get file"
The idea is to NOT use the sftp -b option where an external file listing commands is loaded.
scripting sftp
The following command sends one command to sftp using one line:
sftp -o PasswordAuthentication=no user@host" <<<"lcd /home"
How to send multiple lines to sftp using one line. Is there a way to insert carriage returns or something to achieve this, for example:
sftp -o PasswordAuthentication=no user@host" <<<"lcd /homen cd /myhomen get file"
The idea is to NOT use the sftp -b option where an external file listing commands is loaded.
scripting sftp
scripting sftp
edited Nov 8 '12 at 23:09
Gilles
529k12810601585
529k12810601585
asked Nov 8 '12 at 13:51
Radnaskela Samot
71118
71118
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
From the here-string (<<<) syntax you used I guess your shell is bash, so you can also use string with backslash-escaped characters ($''):
sftp -o PasswordAuthentication=no user@host <<< $'lcd /homen cd /myhomen get file'
The portable alternative is here-document:
sftp -o PasswordAuthentication=no user@host <<END
lcd /home
cd /myhome
get file
END
1
<<<was introduced first by zsh (though inspired byrc) and was later added to ksh93 and then bash.
– Stéphane Chazelas
Nov 8 '12 at 22:34
Thank you, @StephaneChazelas. I really need to strengthen myzshskills.
– manatwork
Nov 9 '12 at 8:49
add a comment |
Use the -b/--batchfile option to have proper error handling:
printf '%sn' 'lcd /home' 'cd /myhome' 'get file' | sftp -b - user@host
1
To use variables change ' to "
– Radnaskela Samot
Nov 9 '12 at 8:43
add a comment |
Yes, you can just use echo -e
echo -e "lcd /homencd /myhomenget file" | sftp user@host
3
echois very non-standard -echo -edoesn't work the same everywhere, so you'd have to check first. Alternatively, just useprintfwhich is much more portable and should work the same everywhere.
– jw013
Nov 8 '12 at 16:59
add a comment |
It is not necessary to avoid the -b option to avoid writing the batch file to disk. Using process substitution you can create the batch on the fly.
batch() {
echo lcd /home
echo cd /myhome
echo get file
}
sftp -b <(batch) -o PasswordAuthentication=no user@host
add a comment |
Use native sftp command
sftp -o PasswordAuthentication=no user@host:/home/myhome/file
What you didn't notice was thatlcdandcddo different things. You've just combined the paths into something that will not exist.
– underscore_d
Aug 14 '18 at 13:14
add a comment |
Mybru, you can mos pipe your commands like so:
echo '
lcd /home
cd /myhome
get file
' | sftp -o PasswordAuthentication=no user@host
New contributor
Paque Mann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f55190%2fhow-to-send-multiple-commands-to-sftp-using-one-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
From the here-string (<<<) syntax you used I guess your shell is bash, so you can also use string with backslash-escaped characters ($''):
sftp -o PasswordAuthentication=no user@host <<< $'lcd /homen cd /myhomen get file'
The portable alternative is here-document:
sftp -o PasswordAuthentication=no user@host <<END
lcd /home
cd /myhome
get file
END
1
<<<was introduced first by zsh (though inspired byrc) and was later added to ksh93 and then bash.
– Stéphane Chazelas
Nov 8 '12 at 22:34
Thank you, @StephaneChazelas. I really need to strengthen myzshskills.
– manatwork
Nov 9 '12 at 8:49
add a comment |
From the here-string (<<<) syntax you used I guess your shell is bash, so you can also use string with backslash-escaped characters ($''):
sftp -o PasswordAuthentication=no user@host <<< $'lcd /homen cd /myhomen get file'
The portable alternative is here-document:
sftp -o PasswordAuthentication=no user@host <<END
lcd /home
cd /myhome
get file
END
1
<<<was introduced first by zsh (though inspired byrc) and was later added to ksh93 and then bash.
– Stéphane Chazelas
Nov 8 '12 at 22:34
Thank you, @StephaneChazelas. I really need to strengthen myzshskills.
– manatwork
Nov 9 '12 at 8:49
add a comment |
From the here-string (<<<) syntax you used I guess your shell is bash, so you can also use string with backslash-escaped characters ($''):
sftp -o PasswordAuthentication=no user@host <<< $'lcd /homen cd /myhomen get file'
The portable alternative is here-document:
sftp -o PasswordAuthentication=no user@host <<END
lcd /home
cd /myhome
get file
END
From the here-string (<<<) syntax you used I guess your shell is bash, so you can also use string with backslash-escaped characters ($''):
sftp -o PasswordAuthentication=no user@host <<< $'lcd /homen cd /myhomen get file'
The portable alternative is here-document:
sftp -o PasswordAuthentication=no user@host <<END
lcd /home
cd /myhome
get file
END
answered Nov 8 '12 at 14:51
manatwork
21.6k38384
21.6k38384
1
<<<was introduced first by zsh (though inspired byrc) and was later added to ksh93 and then bash.
– Stéphane Chazelas
Nov 8 '12 at 22:34
Thank you, @StephaneChazelas. I really need to strengthen myzshskills.
– manatwork
Nov 9 '12 at 8:49
add a comment |
1
<<<was introduced first by zsh (though inspired byrc) and was later added to ksh93 and then bash.
– Stéphane Chazelas
Nov 8 '12 at 22:34
Thank you, @StephaneChazelas. I really need to strengthen myzshskills.
– manatwork
Nov 9 '12 at 8:49
1
1
<<< was introduced first by zsh (though inspired by rc) and was later added to ksh93 and then bash.– Stéphane Chazelas
Nov 8 '12 at 22:34
<<< was introduced first by zsh (though inspired by rc) and was later added to ksh93 and then bash.– Stéphane Chazelas
Nov 8 '12 at 22:34
Thank you, @StephaneChazelas. I really need to strengthen my
zsh skills.– manatwork
Nov 9 '12 at 8:49
Thank you, @StephaneChazelas. I really need to strengthen my
zsh skills.– manatwork
Nov 9 '12 at 8:49
add a comment |
Use the -b/--batchfile option to have proper error handling:
printf '%sn' 'lcd /home' 'cd /myhome' 'get file' | sftp -b - user@host
1
To use variables change ' to "
– Radnaskela Samot
Nov 9 '12 at 8:43
add a comment |
Use the -b/--batchfile option to have proper error handling:
printf '%sn' 'lcd /home' 'cd /myhome' 'get file' | sftp -b - user@host
1
To use variables change ' to "
– Radnaskela Samot
Nov 9 '12 at 8:43
add a comment |
Use the -b/--batchfile option to have proper error handling:
printf '%sn' 'lcd /home' 'cd /myhome' 'get file' | sftp -b - user@host
Use the -b/--batchfile option to have proper error handling:
printf '%sn' 'lcd /home' 'cd /myhome' 'get file' | sftp -b - user@host
answered Nov 8 '12 at 22:33
Stéphane Chazelas
300k54564913
300k54564913
1
To use variables change ' to "
– Radnaskela Samot
Nov 9 '12 at 8:43
add a comment |
1
To use variables change ' to "
– Radnaskela Samot
Nov 9 '12 at 8:43
1
1
To use variables change ' to "
– Radnaskela Samot
Nov 9 '12 at 8:43
To use variables change ' to "
– Radnaskela Samot
Nov 9 '12 at 8:43
add a comment |
Yes, you can just use echo -e
echo -e "lcd /homencd /myhomenget file" | sftp user@host
3
echois very non-standard -echo -edoesn't work the same everywhere, so you'd have to check first. Alternatively, just useprintfwhich is much more portable and should work the same everywhere.
– jw013
Nov 8 '12 at 16:59
add a comment |
Yes, you can just use echo -e
echo -e "lcd /homencd /myhomenget file" | sftp user@host
3
echois very non-standard -echo -edoesn't work the same everywhere, so you'd have to check first. Alternatively, just useprintfwhich is much more portable and should work the same everywhere.
– jw013
Nov 8 '12 at 16:59
add a comment |
Yes, you can just use echo -e
echo -e "lcd /homencd /myhomenget file" | sftp user@host
Yes, you can just use echo -e
echo -e "lcd /homencd /myhomenget file" | sftp user@host
answered Nov 8 '12 at 14:43
utopiabound
2,6611518
2,6611518
3
echois very non-standard -echo -edoesn't work the same everywhere, so you'd have to check first. Alternatively, just useprintfwhich is much more portable and should work the same everywhere.
– jw013
Nov 8 '12 at 16:59
add a comment |
3
echois very non-standard -echo -edoesn't work the same everywhere, so you'd have to check first. Alternatively, just useprintfwhich is much more portable and should work the same everywhere.
– jw013
Nov 8 '12 at 16:59
3
3
echo is very non-standard - echo -e doesn't work the same everywhere, so you'd have to check first. Alternatively, just use printf which is much more portable and should work the same everywhere.– jw013
Nov 8 '12 at 16:59
echo is very non-standard - echo -e doesn't work the same everywhere, so you'd have to check first. Alternatively, just use printf which is much more portable and should work the same everywhere.– jw013
Nov 8 '12 at 16:59
add a comment |
It is not necessary to avoid the -b option to avoid writing the batch file to disk. Using process substitution you can create the batch on the fly.
batch() {
echo lcd /home
echo cd /myhome
echo get file
}
sftp -b <(batch) -o PasswordAuthentication=no user@host
add a comment |
It is not necessary to avoid the -b option to avoid writing the batch file to disk. Using process substitution you can create the batch on the fly.
batch() {
echo lcd /home
echo cd /myhome
echo get file
}
sftp -b <(batch) -o PasswordAuthentication=no user@host
add a comment |
It is not necessary to avoid the -b option to avoid writing the batch file to disk. Using process substitution you can create the batch on the fly.
batch() {
echo lcd /home
echo cd /myhome
echo get file
}
sftp -b <(batch) -o PasswordAuthentication=no user@host
It is not necessary to avoid the -b option to avoid writing the batch file to disk. Using process substitution you can create the batch on the fly.
batch() {
echo lcd /home
echo cd /myhome
echo get file
}
sftp -b <(batch) -o PasswordAuthentication=no user@host
answered Jan 18 '17 at 10:38
ceving
1,70421321
1,70421321
add a comment |
add a comment |
Use native sftp command
sftp -o PasswordAuthentication=no user@host:/home/myhome/file
What you didn't notice was thatlcdandcddo different things. You've just combined the paths into something that will not exist.
– underscore_d
Aug 14 '18 at 13:14
add a comment |
Use native sftp command
sftp -o PasswordAuthentication=no user@host:/home/myhome/file
What you didn't notice was thatlcdandcddo different things. You've just combined the paths into something that will not exist.
– underscore_d
Aug 14 '18 at 13:14
add a comment |
Use native sftp command
sftp -o PasswordAuthentication=no user@host:/home/myhome/file
Use native sftp command
sftp -o PasswordAuthentication=no user@host:/home/myhome/file
answered Dec 19 '13 at 0:55
Markomafs
1013
1013
What you didn't notice was thatlcdandcddo different things. You've just combined the paths into something that will not exist.
– underscore_d
Aug 14 '18 at 13:14
add a comment |
What you didn't notice was thatlcdandcddo different things. You've just combined the paths into something that will not exist.
– underscore_d
Aug 14 '18 at 13:14
What you didn't notice was that
lcd and cd do different things. You've just combined the paths into something that will not exist.– underscore_d
Aug 14 '18 at 13:14
What you didn't notice was that
lcd and cd do different things. You've just combined the paths into something that will not exist.– underscore_d
Aug 14 '18 at 13:14
add a comment |
Mybru, you can mos pipe your commands like so:
echo '
lcd /home
cd /myhome
get file
' | sftp -o PasswordAuthentication=no user@host
New contributor
Paque Mann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Mybru, you can mos pipe your commands like so:
echo '
lcd /home
cd /myhome
get file
' | sftp -o PasswordAuthentication=no user@host
New contributor
Paque Mann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Mybru, you can mos pipe your commands like so:
echo '
lcd /home
cd /myhome
get file
' | sftp -o PasswordAuthentication=no user@host
New contributor
Paque Mann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Mybru, you can mos pipe your commands like so:
echo '
lcd /home
cd /myhome
get file
' | sftp -o PasswordAuthentication=no user@host
New contributor
Paque Mann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Paque Mann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 1 hour ago
Paque Mann
1
1
New contributor
Paque Mann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Paque Mann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Paque Mann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f55190%2fhow-to-send-multiple-commands-to-sftp-using-one-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown