Is it possible to run some SSH commands using SFTP?
You can only run commands on the local system using SFTP. Run help
to see what commands are available:
sftp> help
Available commands:
bye Quit sftp
cd path Change remote directory to 'path'
chgrp grp path Change group of file 'path' to 'grp'
chmod mode path Change permissions of file 'path' to 'mode'
chown own path Change owner of file 'path' to 'own'
df [-hi] [path] Display statistics for current directory or
filesystem containing 'path'
exit Quit sftp
get [-afPpRr] remote [local] Download file
reget [-fPpRr] remote [local] Resume download file
reput [-fPpRr] [local] remote Resume upload file
help Display this help text
lcd path Change local directory to 'path'
lls [ls-options [path]] Display local directory listing
lmkdir path Create local directory
ln [-s] oldpath newpath Link remote file (-s for symlink)
lpwd Print local working directory
ls [-1afhlnrSt] [path] Display remote directory listing
lumask umask Set local umask to 'umask'
mkdir path Create remote directory
progress Toggle display of progress meter
put [-afPpRr] local [remote] Upload file
pwd Display remote working directory
quit Quit sftp
rename oldpath newpath Rename remote file
rm path Delete remote file
rmdir path Remove remote directory
symlink oldpath newpath Symlink remote file
version Show SFTP version
!command Execute 'command' in local shell
! Escape to local shell
? Synonym for help
As can be seen, there's no SFTP command that:
- allows running commands on the remote system. There's only
!
for local commands. - allows appending to or editing a file. You can get the file, edit it locally and put it back.
I wouldn't expect anything like this to exist, since a common use case for SFTP is to jail users and provide file access without the ability to run any commands.
Instead of zipping, maybe use the -C
option with sftp
:
-C Enables compression (via ssh's -C flag).
Related videos on Youtube
wpcoder
Updated on September 18, 2022Comments
-
wpcoder over 1 year
Having me not knowing much about Ubuntu; this is my first question here. So excuse me if it looks invalid question.
I was told that its possible to run some SSH commands using SFTP.
If that is possible; what are the list of supported commands to run over SFTP remotely? (SSH commands or SSH emulation); not the PUT, GET etc..
The scenario I am trying to achieve is the following:
- Zip some big number of files.
- Upload through sFTP.
- Unzip using sFTP (if supported); Not by SSH
Or at least if that is possible; to crease some bash script and run through sFTP
Update: I have another related question; Is it possible to edit a file using SFTP? Append or edit one line in remote file?
Dose that need sFTP server combatibilty?
Please advice and if you can share a link to the full list or further reading! Thank you
-
sudodus over 6 yearsIf you have permissions, you can connect to a server via
ssh
in one terminal window andsftp
in another window side by side. So you need not (and cannot) runssh
commands usingsftp
.
-
wpcoder over 6 yearsdose this applies to sftp? how to implement in WinSCP? without a terminal
-
wpcoder over 6 yearsDose this means that the sftp protocol doesn't support shell commands? From remote client or WinSCP; a bit confused, I can see that WinSCP can send commands via same sftp connection , port 22 , so I guess its supported by sftp; is this right?
-
muru over 6 years@wpcoder it's a file transfer protocol. There's no reason for it support shell commands
-
wpcoder over 6 yearsI am just making a research if that is possible, one sftp vendor's admin told me that sftp protocol support zip/unzip and remote file edit..just need to confirm... sftp protocol not ssh protocol. Thank you
-
Rinzwind over 6 yearsNo and you cant. Command line only.