FTP_transfer/upload.cpp
2024-09-12 18:40:56 +08:00

34 lines
1.1 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 此程序演示采用开发框架的cftpclient类上传文件。
*/
#include "_ftp.h"
using namespace eviwbh;
int main(int argc,char *argv[])
{
cftpclient ftp;
// 登录远程ftp服务器请改为你自己服务器的ip地址。
if (ftp.login("192.168.150.128:21","eviwbh","password") == false)
{
printf("ftp.login(192.168.150.128:21,eviwbh/password) failed.\n"); return -1;
}
// 在ftp服务器上创建/home/eviwbh/tmp注意如果目录已存在会返回失败。
if (ftp.mkdir("/home/eviwbh/tmp")==false) { printf("ftp.mkdir() failed.\n"); return -1; }
// 把ftp服务器上的工作目录切换到/home/eviwbh/tmp
if (ftp.chdir("/home/eviwbh/tmp")==false) { printf("ftp.chdir() failed.\n"); return -1; }
// 把本地的demo51.cpp上传到ftp服务器的当前工作目录。
if (ftp.put("demo51.cpp","demo51.cpp")==true)
printf("put demo51.cpp ok.\n");
else
printf("put demo51.cpp failed.\n");
// 如果不调用chdir切换工作目录以下代码采用全路径上传文件。
// ftp.put("/project/public/demo/demo51.cpp","/home/eviwbh/tmp/demo51.cpp");
}