资源简介
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文件格式详解中文
相关资源
- FTP课程设计(服务端+客户端)
- python实现的ftp自动上传、下载脚本
- 用Socket编程实现FTP
- tftp文件传输工具
- linux 网络实验 ftp程序
- 用Socket写的简易FTP服务器和客户端
- 基于C 的简易FTP客户端(带源码)
- 用IdFTPServer写的一个FTPServer程序
- FTP命令详解.doc
- 一个简单方便的服务端ftp搭建工具
- 20cn的ftp服务器超好用 简洁
- 最好用的FTP服务器
- CuteFTP8.0绿色破解版免安装无需序列号
- PSFTP.EXE 工具
- CuteFTP8.0简体中文破解版
- Wing FTP Server FTP服务器 v6.1.9
- 易语言绵绵FTP网络验证操作模块源码
- 免费的2014ftp暴力破解扫描工具可自动
- linux c下的ftp客户端和服务器端
- Notepad++ ftp/sftp 插件
- 8uftp安装
- Xshell6+Xftp6绿色_破解版解压后点击绿色
- ftp断点续传,ftp协议网络抓拍数据
- redhat vsftp
- Windows Server 2016 部署FTP服务器
- 1688图片采集工具 v3.0.0.4.zip
- Qt之FTP客户端
- 编译通过的Sipek.SoftPhone
- Linux课设实现ftp服务器和客户端
- Renci.SshNet.dll及其文档和实现SSH、SCP、
评论
共有 条评论