初心者向け - Beginners

Learn how to use the sftp command!

en-how-to-sftp

Hello! I’m Shunsuke.

I’m a web engineer at a global company.

This site provides information for beginners who are studying programming to become web engineers.

This time, I received this question.

Teach me how to use the sftp command!

It’s a command I don’t use that often, so I look it up every time too. lol

In this article, I’ll explain this question!

What is the sftp command?

The sftp command is used to exchange files with the server.

Used to place files on the server and retrieve files from the server.

If you use it frequently, it’s easier to use a client like Cyberduck.

How to use the sftp command!

It is assumed that the host has been registered in ~/.ssh/config.

If you haven’t registered your host, try setting it up this way!

en-ssh-config-setting
Register host in ~/.ssh/config for easy ssh!"It's so annoying to type ssh commands! Can't you do something about it?" It's hard when you have to type the ssh command every time. So in this article, I'll explain how to solve this problem!...

Connect to the server

Connect to the server using the sftp command.

XXXXX should be the host name of the server registered in config.

$ sftp XXXXX

Retrieve a file

Retrieve a file from the server.

As with ssh, you can use cd and ls, so use those to find the file location!

sftp> get xxxx.txt

Placing Files

Place the file on the server.

You can specify the file path as a full path or as a path relative to the connected directory.

sftp> put xxxx.txt

Exit the sftp command

Disconnects communication with the server.

Surprisingly, few people know the disconnect command.

sftp> quit
sftp> bye

I’ve always used control + D to disconnect.
It works the same no matter which method you use.

Summary

This is a summary of the basic usage of the sftp command.

For simple file transfers, I like to use the command.

Basically, it’s just get and put, so it’s easy to remember compared to other commands!

From now on, I won’t have to look them up to use them!

Afterword

I use this command when I want to retrieve files from the server, but I don’t need to use the client for this purpose.

When you get used to it, it’s faster to use the sftp command than to configure the client.

It’s safer to use the client, though.