方法一:使用FTP工具下载并安装FTP客户端软件,比如;
方法一:使用FTP工具
1. 下载并安装FTP客户端软件,比如FileZilla;
2. 打开FileZilla,在服务器设置中输入Linux服务器的IP地址、用户名和密码;
3. 在本地文件夹中找到要上传的文件,右键点击文件,选择“上传”;
4. 文件会被上传到Linux服务器的指定位置。
代码:
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
int client_sock;
char buf[1024];
struct sockaddr_in server_addr;
int bytes_sent, bytes_received;
// 创建socket
client_sock = socket(AF_INET, SOCK_STREAM, 0);
if (client_sock == -1)
{
printf("socket error\n");
return -1;
}
// 设置服务器地址
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(21);
server_addr.sin_addr.s_addr = inet_addr("192.168.1.1");
// 连接服务器
if (connect(client_sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1)
{
printf("connect error\n");
return -1;
}
// 接收服务器提示
bytes_received = recv(client_sock, buf, 1024, 0);
if (bytes_received == -1)
{
printf("recv error\n");
return -1;
}
else
{
buf[bytes_received] = '\0';
printf("%s", buf);
}
// 发送用户名
strcpy(buf, "USER username\r\n");
bytes_sent = send(client_sock, buf, strlen(buf), 0);
if (bytes_sent == -1)
{
printf("send error\n");
return -1;
}
// 接收服务器提示
bytes_received = recv(client_sock, buf, 1024, 0);
if (bytes_received == -1)
{
printf("recv error\n");
return -1;
}
else
{
buf[bytes_received] = '\0';
printf("%s", buf);
}
// 发送密码
strcpy(buf, "PASS password\r\n");
bytes_sent = send(client_sock, buf, strlen(buf), 0);
if (bytes_sent == -1)
{
printf("send error\n");
return -1;
}
// 接收服务器提示
bytes_received = recv(client_sock, buf, 1024, 0);
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(61条)