资源简介
linux客户端,实现上传和下载功能,不支持断点续传
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include “damd_ftp.h“
#define _DEBUG 0 //by zhouq
bool DAMD_FtpGetReply(FPT_FTP* ftp)
{
char recvbuf[FTP_BUFSIZE];
if (ftp->CommandChunnel==INVALID_SOCKET)
{
printf(“Does not connect\n“);
return false;
}
ftp->nReplyCode = 0;
memset(ftp->szReplyString 0 FTP_BUFSIZE);
while (DAMD_SockSelect(ftp->CommandChunnel FD_READ ftp->nMsTimeOut))
{
memset(recvbuf 0 FTP_BUFSIZE);
if (DAMD_SockReceive(ftp->CommandChunnel recvbuf FTP_BUFSIZE-1)<=0)
{
printf(“Receive reply failed\n“);
return false;
}
#ifdef _DEBUG
printf(recvbuf);
#endif
if(strncmp(recvbuf“550“3)==0)
{
printf(“ Failed to open file.\n“);
return false; //文件不存在
}
if (recvbuf[strlen(recvbuf)-1]==‘\n‘)
{
char* lastline = recvbuf+strlen(recvbuf)-2;
for(; *lastline!=‘\n‘ && lastline>recvbuf; lastline--);
if (*lastline==‘\n‘)
lastline++;
if (lastline[3] == ‘ ‘)
{
ftp->nReplyCode = atoi(lastline);
strcpy(ftp->szReplyString lastline+4);
return true;
}
}
}
return false;
}
int DAMD_FtpSendCommand(FPT_FTP* ftp const char* lpszCommand)
{
char command[256];
if (ftp->CommandChunnel==INVALID_SOCKET)
{
printf(“Does not connect\n“);
return 111;
}
#ifdef _DEBUG
if (strncmp(lpszCommand “PASS “ 5)!=0)
printf(“CMD>%s\n“ lpszCommand);
else
printf(“CMD>PASS *****\n“);
#endif
sprintf(command “%s\r\n“ lpszCommand);
if (DAMD_SockSend(ftp->CommandChunnel command strlen(command))<=0)
{
printf(“Send command ‘%s‘ failed\n“ lpszCommand);
return false;
}
return DAMD_FtpGetReply(ftp);
}
FPT_FTP* DAMD_FtpConnect(const char* lpszHostAddress const char* lpszUser const char* lpszPassword)
{
u_int nFtpPort;
struct protoent * lpProtocol;
char szCommand[256];
FPT_FTP* ftp = (FPT_FTP*)malloc(sizeof(FPT_FTP));
ftp->CommandChunnel = INVALID_SOCKET;
ftp->DataChunnel = INVALID_SOCKET;
ftp->pFtpList = NULL;
ftp->nFtpListCount = 0;
ftp->nTransferMode = FPD_ModePassive;
ftp->nTransferType = FPD_TypeBinary;
ftp->nReplyCode = 0;
ftp->nMsTimeOut = 60000;
memset(ftp->szReplyString 0 FTP_BUFSIZE);
ftp->CommandChunnel = DAMD_SockCreate(0 SOCK_STREAM);
if (ftp->CommandChunnel == INVALID_SOCKET)
{
printf(“Can not create socket\n“);
free(ftp);
return (ftp = NULL);
}
lpProtocol = getprotobyname(“ftp“);
if (lpProtocol==NULL)
nFtpPort = 21;
else
nFtpPort = lpProtocol->p_proto;
if (!DAMD_SockConnect(ftp->CommandChunnel lpszHostAddress nFtpPort))
{
printf(“Connect to %s failed\n“ lpszHostAddress);
free(ftp);
DAMD_SockClose(ftp->CommandChunnel);
return (ftp = NULL);
}
DAMD_FtpGetReply(ftp);
if (!lpszUser || !*lpszUser)
strcpy(szCommand “USER Anonymous“);
else
sprintf(szCommand “USER %s“ lpszUser);
if
- 上一篇:100多个漂亮的ICO图片,EPS格式!
- 下一篇:ELF文件格式详解中文
相关资源
- proftpd虚拟用户挂载多个目录
- ftp-0.17-51.1.el6.x86_64.rpm
- c的ftp断点续传的客户端源代码
- PB9使用api实现ftp查看与的源码
- 利用winsock编程来实现FTP协议客户端
- fluentftp组件
- LINUX-FTP服务包 vsftpd-2.0.1-5.src.rpm
- 批量验证FTP帐号密码
- tftp固件升级代码
- qt 实现ftp服务器源码
- OSIsoftPI实时数据库技术资料合集
- qtftp-master
- vsftp的安装包
- QFTP类实现FTP上传、、删除文件及文件
- windows下的tftp服务器和客户端软件包含
- edtFTPnetPro v8.6.5
- LinuxFTP简单实现、
- 简易FtpServer
- ftp爆破工具
- nginx转发sftp、ftp的配置
- tftp刷路由利器
- FTP客户端的设计
- ftpServer_windows下超简单的ftp服务器
- FTP客户端服务器端全部代码
- linux环境下基于socket通信的ftp系统
- MicroSoftProject
- FTP协议(中文版).pdf
- destoon7设置远程FTP图片服务器.docx
- vsftpd-3.0.2-27.el7.x86_64.rpm
- powerbuilder10.5通过调用FTP实现程序自动
评论
共有 条评论