在Ubuntu系统中,你可以使用scp
(Secure Copy Protocol)命令来通过SSH传输文件。以下是使用scp
命令传输文件的基本步骤:
打开终端(Terminal)。
使用以下命令格式来传输文件:
从本地传输到远程服务器:
scp /path/to/local/file username@remote_host:/path/to/remote/directory
从远程服务器传输到本地:
scp username@remote_host:/path/to/remote/file /path/to/local/directory
其中:
/path/to/local/file
是你要传输的本地文件的路径。username
是你在远程服务器上的用户名。remote_host
是远程服务器的IP地址或主机名。/path/to/remote/directory
是远程服务器上的目标目录路径。/path/to/remote/file
是你要从远程服务器传输的文件的路径。如果远程服务器使用的是非标准SSH端口,你可以使用-P
选项指定端口号:
scp -P port_number /path/to/local/file username@remote_host:/path/to/remote/directory
如果你需要传输整个目录,可以使用-r
选项来递归复制:
scp -r /path/to/local/directory username@remote_host:/path/to/remote/directory
如果你想在传输过程中保持文件的修改时间和访问时间,可以使用-p
选项:
scp -p /path/to/local/file username@remote_host:/path/to/remote/directory
如果你想在传输过程中加密并压缩文件,可以使用-C
选项:
scp -C /path/to/local/file username@remote_host:/path/to/remote/directory
执行命令后,系统会提示你输入远程服务器用户的密码。输入密码后,文件传输将开始。
请注意,为了使用scp
命令,你需要确保本地计算机上已经安装了SSH客户端,并且你有权限访问远程服务器。如果你还没有设置SSH密钥认证,你可能需要手动输入密码来完成文件传输。