c++ ftplib 连接ftp与创建文件夹

261 篇文章 10 订阅


#include "ftplib.h"

void _CreateDir()
{
    ftplib *ftp = new ftplib();
    int ret = ftp->Connect("127.0.0.1:21");
    if (ret != 1)
    {
        //连接失败
    }
    ret = ftp->Login("test", "123456");
    if (ret != 1)
    {
        //登录失败
    }

    //1、创建文件夹
    ret = ftp->Mkdir("newDir");
    if (ret != 1)
    {
        //创建文件夹失败
    }

    //ret = ftp->Get("text.txt", "text.txt", ftplib::image);
    ret = ftp->Quit();
    if (ret != 1)
    {
        //退出失败
    }

    delete ftp;
    ftp = nullptr;
}
实现的结果:

 

成功创建了新的文件夹

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
FTP Library Routines Release 4.0 Thomas Pfau (tfpfau@gmail.com) June 7, 2013 This package implements a callable interface to FTP. The FTP protocol is specified in RFC 959. The library has been tested on linux, OpenVMS and Windows NT. It should also work without major modification on other POSIX systems. All programs using the library should include ftplib.h. FTP开源库。 Miscellaneous Functions FtpInit() - Initialize the library FtpSite() - Send a 'SITE' command FtpLastResponse() - Retrieve last server response FtpSysType() - Determine remote system type FtpSize() - Determine size of remote file FtpSizeLong() - Determine size of remote file FtpModDate() - Determine modification time of file FtpSetCallback() - Establish a callback function FtpClearCallback() - Remove a callback function Server Connection FtpConnect() - Connect to a remote server FtpLogin() - Login to remote machine FtpQuit() - Disconnect from remote server FtpOptions() - Set Connection Options Directory Functions FtpChdir() - Change working directory FtpMkdir() - Create a directory FtpRmdir() - Remove a directory FtpDir() - List a remote directory FtpNlst() - List a remote directory FtpCDUp() - Change to parent directory FtpPwd() - Determine current working directory File to File Transfer FtpGet() - Retreive a remote file FtpPut() - Send a local file to remote FtpDelete() - Delete a remote file FtpRename() - Rename a remote file File to Program Transfer These routines allow programs access to the data streams connected to remote files and directories. FtpAccess() - Open a remote file or directory FtpRead() - Read from remote file or directory FtpWrite() - Write to remote file FtpClose() - Close data connection Utilities qftp - Command line ftp utility
在Python中连接FTP服务器并创建文件可以通过使用ftplib库实现。首先,你需要创建一个FTP对象并连接到服务器。然后,使用login函数登录到服务器。接下来,你可以使用mkd函数创建文件。下面是一个示例代码: import ftplib host = '192.168.11.50' ftp = ftplib.FTP() ftp.connect(host, 21001) ftp.login('ftpuser', 'XXXXXXXXXXX') folder_name = '新文件' ftp.mkd(folder_name) ftp.quit() 这样,你就可以连接FTP服务器并创建一个名为"新文件"的文件。请确保替换host,登录凭据和文件名称为你自己的值。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [python连接FTP服务器](https://blog.csdn.net/gc_2299/article/details/123674840)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [【Python基础学习】—文件和文件操作](https://blog.csdn.net/dream_successor/article/details/93489340)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值