SFTP Command Line Examples without Prompt

If you want to transfer a file between two devices, especially PC to iPhone, you definitely should run the SSH File Transfer Protocol. Of course, to run it, you will be allowed to use any command lines which you will see on the program.

Well, to run it, you will be required to enter the password prompt, sometimes it is a hard way to do because of some issues. Then, you may be looking for the ways to use SFTP without using a password prompt. Is it possible to use the SFTP command line without a password prompt. So, let’s see the command line examples that you can use to run it!

SFTP Command Line Examples without Prompt

SFTP Command Line Examples without Prompt

If you want to run SFTP command line without prompt, it may either be a success or a failure. However, to use SFTP command line, you surely have to enter the password prompt to get the access. Without a password prompt, to get access to SFTP is just a bit of hope at all.

But, if you are curious to use SFTP command line without password prompt, it is totally not wrong if you use some examples of SFTP command lines that we will show below. It means that you can try to use the examples of command lines that will allow you to get access to SFTP. Here are the SFTP command line examples without Prompt:

Example 1 – Use “sshpass” Command Line

You can use “sshpass” command line following:

sshpass -p ‘password’ ssh username@hostname

or you can use the following script for ‘ftp’ command instead of ‘sftp’:






ftp -n $HOST <<EOF

quote USER $USER


get $FILE



Example 2- Use ncftp

You can also use ncftp in a file and use it as following command line:

ncftpget -f login.cfg [*options*] *local-directory* *remote-files…*

Example 3 – Use the code in a shell script

You can use these codes in a shell script, that’s totally not asking for a password prompt.

ftp -n -v << ENDFTP

open test_ftp.server

user ftp_user_name ftp_password



Example 4 – Install SSH keys

To run SFTP command line without password prompt, you can also install ssh keys for the users which connects using the scripts as follow:

ftp -n -v << ENDFTP

open test_ftp.server

user ftp_user_name ftp_password



Here, the root access is generally blocked by sftp (ssh protocol)

ssh-keygen: password-less SSH login

Example 5 – Copy the public key of Server A to Server B

If you consider having Server A and Server B. Then, you want to connect from A to B without password prompt. Well, since you’ve generated the keys, you surely can copy the public key of Server A (id_Xsa.pub, whereX=d or r). Then, paste it on Server B  (under <user home directory>/.ssh) directory of desired user as authorized_keys.

Well, Server A public key (id_Xsa.pub) is successfully copied to Server B as authorized_keys.

Example 6: With having ssh-copy-id

That is a simple way to do it if you want to run SFTP Command line without prompt. Here is the command line:

ssh-copy-id username@host

Example 7: Write your SFTP command

After you already have the keys set up properly. It means that you have done an initial connection manually that makes the recipient be informed in your own known_hosts file. It is time to prepare your script, then write sftp commands into a file. Run it with the -b option.

sftp -b ${sftpCommandScript} ${userid}@${remoteHost}

the sftp command script file contains things as follow:

put fromfilename tofilename

chmod 664 tofilename

Well, those are some examples of SFTP command line which will not ask you to enter the password prompt.

Other SFTP Commands and Options

There are a lot of command line options of SFTP which can be incorporated as well as an example of SFTP use.

SFTP connection command format

The values will be displayed in “< >” represent variables. Then, “< >” signs are not used in the input as following command line:

sftp [-Cv] [-B <buffer_size>] [-b <batchfile>] [-F <ssh_config>][-o <ssh_option] [-P <sftp_server_path>] [-R <#_of_requests>][-S <program>] [-s <subsystem | sftp_server>] hostsftp [[user@]host[:file [file]]]sftp [[user@]host[:dir[/]]]sftp -b <batchfile> [user@]host

Here is the example of SFTP connection which uses the OpenSSH SFTP client from a command line.

#> sftp -i <private key> sshacs@nsmediadocs.sftp.upload.akamai.com

Connected to sshacs@nsmediadocs.sftp.upload.akamai.com.

Connection Command Options

Those command options will cover the command options available for use during the connection process.

Command Descriptions
-1 Use SSH protocol 1
-B <buffer_size> Add this option and set the “<buffer_size>” variable to a desired new file transfer.
-b <batch file> Add this command and set the “<batch file>” variable to the command file.
-C Use compression
-F <ssh_config> Point a substitute per-user SSH configuration file, defining it as the “<ssh_config>” variable
-o <ssh_option> Send the specified “<ssh_option>” to SSH in the ssh_config format.

  • AddressFamily
  • BatchMode
  • BindAddress
  • ChallengeResponseAuthentication
  • CheckHostIP
  • Cipher
  • Ciphers
  • Compression
  • CompressionLevel
  • ConnectionAttempts
  • ConnectTimeout
  • ControlMaster
  • ControlPath
  • GlobalKnownHostsFile
  • GSSAPIAuthentication
  • GSSAPIDelegateCredentials
  • HashKnownHosts
  • Host
  • HostbasedAuthentication
  • HostKeyAlgorithm
  • HostKeyAlias
  • HostName
  • IdentityFile
-o <ssh_option> (cont.)
  • IdentitiesOnly
  • KbdInteractiveDevices
  • LogLevel
  • MACs
  • NoHostAuthenticationForLocalHost
  • NumberOfPasswordPrompts
  • PasswordAuthentication
  • Port
  • PreferredAuthentications
  • Protocol
  • ProxyCommand
  • PubKeyAuthentication
  • RekeyLimit
  • RhostsRSAAuthentication
  • RSAAuthentication
  • SendEnv
  • ServerAliveInterval
  • ServerAliveCountMax
  • SmartcardDevice
  • StrictHostKeyChecking
  • TCPKeepAlive
  • UsePrivilegedPort
  • User
  • UserKnownHostsFile
  • VerifyHostKeyDNS
-P <sftp_server_path> To connect to a local SFTP server without using SSH
-R <#_of _requests> Determine the number of allowed concurrent requests
-S <program> Determine the program  for connecting to the destination
-s <subsystem | sftp_server> Point an SFTP server’s path  or the subsystem for the SSH2 protocol
-v Increase the amount of logging

Interactive SFTP Command Options

cd <path>
chgrp <grp> path
get [-P] <remote-path>
lcd <path>
lls [ls-<options> [<path>]]
lmkdir <path>
ln <oldpath> <newpath>
ls [-<option>] [path]
lumask umask
mkdir <path> 1
put [-P] <local path> [<remote path>]
rename <old path> <new path>
rm <path>
rmdir <path>
symlink <old path> <new path>
! <command>

About SFTP

SFTP stands for Secure File Transfer Protocol which definitely refers to the SSH File Transfer Protocol. SFTP is a variation of the FTP that is one of the oldest internet apps. Both FTP And SFTP are standard definitions, not programs. However, it is up to the others to write an SFTP program, but they have to follow the SFTP standar to make it compatible with other SFTP programs.

Leave a Reply

Your email address will not be published. Required fields are marked *