SSH文件传输命令 scp

若未安装ssh,可以参考:https://blog.csdn.net/m0_37864814/article/details/82626778

 

1、传输文件

scp  /source  username@ip:/destination

2、传输目录(文件夹)

scp -rp /source username@ip:/destination

3、说明

      /source是准备传输的本地文件或者目录的路径,/destination是准备传输到目标主机(usrname@ip)的目标路径;

      username表示远程主机用户名,ip指远程主机ip地址;

      交换源路径和目标路径可以实现将远程主机文件拷贝到本地。

根据题目要求,设计的fcp命令系统需要支持以下接口: 1. fcp <source> [target]:将源文件复制到目标文件中。 2. fcp /?:显示fcp命令的帮助信息。 下面是fcp命令系统的源代码设计: ``` #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> void show_help() { printf("Usage: fcp <source> [target]\n"); printf("Copy source file to target file.\n"); } int main(int argc, char* argv[]) { if (argc == 2 && strcmp(argv[1], "/?") == 0) { show_help(); return 0; } if (argc != 3) { printf("Invalid arguments.\n"); show_help(); return 1; } char* source_path = argv[1]; char* target_path = argv[2]; FILE* source_file = fopen(source_path, "rb"); if (source_file == NULL) { printf("Failed to open source file.\n"); return 1; } struct stat source_stat; if (stat(source_path, &source_stat) != 0) { printf("Failed to get source file stat.\n"); return 1; } FILE* target_file = fopen(target_path, "wb"); if (target_file == NULL) { printf("Failed to open target file.\n"); return 1; } int buffer_size = 1024 * 1024; char* buffer = (char*)malloc(buffer_size); size_t read_size; while ((read_size = fread(buffer, 1, buffer_size, source_file)) > 0) { if (fwrite(buffer, 1, read_size, target_file) != read_size) { printf("Failed to write to target file.\n"); return 1; } } if (fclose(source_file) != 0) { printf("Failed to close source file.\n"); return 1; } if (fclose(target_file) != 0) { printf("Failed to close target file.\n"); return 1; } if (chmod(target_path, source_stat.st_mode) != 0) { printf("Failed to set target file permissions.\n"); return 1; } if (utime(target_path, &source_stat.st_mtim) != 0) { printf("Failed to set target file timestamp.\n"); return 1; } printf("File copied successfully.\n"); return 0; } ``` fcp命令系统的总体结构为:命令行参数解析、文件读写、文件属性设置等模块。 fcp命令系统的模块结构为:主函数模块、帮助信息模块、文件读写模块、文件属性设置模块。 fcp命令系统的接口结构为:show_help()函数用于显示帮助信息,main()函数用于解析命令行参数并调用其他模块的函数完成文件复制和属性设置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值