//---------------------------------------------------------------------------
#include <basepch.h>
#pragma hdrstop
#include "MultiFtp.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TMultiFtp *)
{
new TMultiFtp(NULL);
}
//---------------------------------------------------------------------------
__fastcall TMultiFtp::TMultiFtp(TComponent* Owner)
: TComponent(Owner)
{
lock = false;
isUseFile = false;
runningThreadCnt = 0;
stop = false;
this->Owner = Owner;
}
__fastcall TMultiFtp::~TMultiFtp()
{
fclose(this->globalFile);
if(this->inforImpl.fromToImpl)
delete[] this->inforImpl.fromToImpl;
}
//---------------------------------------------------------------------------
namespace Multiftp
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMultiFtp)};
RegisterComponents("System", classes, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TMultiFtp::FreeMemory()
{
if(this->globalFile)
fclose(this->globalFile);
if(this->inforImpl.fromToImpl)
delete[] this->inforImpl.fromToImpl;
}
SOCKET __fastcall TMultiFtp::ConnectFtp(String host ,int port ,String userName ,String pass)
{
this->DoOnTextOut("欢迎使用funinhand多线程,断点续传软件!!");
MultiThreadDealSocket *dealSocket = new MultiThreadDealSocket();
SOCKET client = dealSocket->GetConnect(host,port);
char * buffer = new char[100];
int recLen ;
recLen = recv(client,buffer,100,0);
buffer[recLen]=0;
if(client == NULL)
{
this->DoOnException("连接ftp服务器失败!");
delete[] buffer;
return NULL;
}
this->DoOnTextOut("连接ftp服务器成功!");
String user = "USER "+userName+" \r\n";
this->DoOnTextOut(user);
send(client,user.c_str(),user.Length(),0);
recLen = recv(client,buffer,100,0);
buffer[recLen]=0;
if(GetCode(buffer) == "331")
{
this->DoOnTextOut("服务器要求验证密码。");
String password = "PASS "+pass+" \r\n";
this->DoOnTextOut(password);
send(client,password.c_str(),password.Length(),0);
recLen = recv(client,buffer,100,0);
buffer[recLen]=0;
int tryTimes = 3;
while(GetCode(buffer) != "230" && tryTimes > 0)
{
send(client,password.c_str(),password.Length(),0);
recLen = recv(client,buffer,100,0);
buffer[recLen]=0;
tryTimes --;
this->DoOnTextOut("第"+IntToStr(3-tryTimes)+"尝试");
}
if(tryTimes < 0)
{
this->DoOnException(userName +"登录失败!");
delete[] buffer;
return NULL;
}
else
this->DoOnTextOut("登录成功!");
}
char *type = "TYPE I \r\n";
this->DoOnTextOut(type);
send(client,type,strlen(type),0);
recLen = recv(client,buffer,100,0);
buffer[recLen]=0;
this->DoOnTextOut(buffer);
delete[] buffer;
return client;
}
void __fastcall TMultiFtp::SetStop(bool stop)
{
this->stop = stop;
}
void __fastcall TMultiFtp::DoOnComplete()
{
if(this->FOnComplete)
this->FOnComplete(this->Owner);
}
void __fastcall TMultiFtp::DoOnGetFileSize(DWORD fileSize)
{
if(this->FOnGetFileSize)
this->FOnGetFileSize(this->Owner,fileSize);
}
void __fastcall TMultiFtp::DoOnTextOut(String text)
{
if(this->FOnTextOut)
{
int index = text.Pos("\r\n");
if(index > 0)
this->FOnTextOut(this->Owner,text.SubString(1,index-1));
else
this->FOnTextOut(this->Owner,text);
}
}
void __fastcall TMultiFtp::DoOnException(String error)
{
if(this->FOnException)
{
int index = error.Pos("\r\n");
if(index > 0)
{
this->FOnException(this->Owner,error.SubString(1,index-1));
}
else
{
this->FOnException(this->Owner,error);
}
}
}
void __fastcall TMultiFtp::DoOnProgress(DWORD pos)
{
if(this->FOnProgress)
this->FOnProgress(this->Owner,pos);
}
void __fastcall TMultiFtp::DoOnGetRate(DWORD cnt)
{
if(this->FOnGetRate)
this->FOnGetRate(this->Owner,cnt);
}
String __fastcall TMultiFtp::GetCode(String revStr)
{
String str;
int index ;
index = revStr.Pos(" ");
str = revStr.SubString(1,index-1);
return str;
}
DWORD __fastcall TMultiFtp::GetFileSize()
{
return this->fileSize;
}
DWORD __fastcall TMultiFtp::GetFtpFileSize(SOCKET client ,String fileName)
{
String size = "SIZE "+this->FFileName+" \r\n";
this->DoOnTextOut(size);
send(client,size.c_str(),size.Length(),0);
char *buffer= new char[100];
int recLen ;
recLen = recv(client,buffer,100,0);
buffer[recLen]=0;
this->DoOnTextOut(buffer);
if(GetCode(buffer) != "213")
{
this->DoOnTextOut("尝试第二次获取");
send(client,size.c_str(),size.Length(),0);
recLen = recv(client,buffer,100,0);
buffer[recLen]=0;
this->DoOnTextOut(buffer);
if(GetCode(buffer) != "213")
{
this->DoOnTextOut("尝试第三次获取");
send(client,size.c_str(),size.Length(),0);
recLen = recv(client,buffer,100,0);
buffer[recLen]=0;
this->DoOnTextOut(buffer);
if(GetCode(buffer) != "213")
{
this->DoOnException("获取文件大小失败!");
delete[] buffer;
return 0;
}
else
{
this->DoOnTextOut(buffer);
}
}
else
{
this->DoOnTextOut(buffer);
}
}
else
{
this->DoOnTextOut(buffer);
}
String recvStr(buffer);
delete[] buffer;
int index = recvStr.Pos("\r\n");
recvStr = recvStr.SubString(1,index-1);
index = recvStr.Pos(" ");
recvStr = recvStr.SubString(index+1,recvStr.Length()- index);
this->fileSize =StrToInt(recvStr);
return this->fileSize;
}
bool __fastcall TMultiFtp::CheckIsSupportMulti(SOCKET client)
{
String rest = "REST 100 \r\n";
char *buffer = new char[100];
this->DoOnTextOut(rest);
int recLen ;
send(client,rest.c_str(),rest.Length(),0);
recLen = recv(client,buffer,100,0);
buffer[recLen]=0;
this->DoOnTextOut(buffer);
if(GetCode(buffer) != "350")
{
delete[] buffer;
return false;
}
delete[] buffer;
return true;
}
FileTail * __fastcall TMultiFtp::GetFilePosLen()
{
while(lock)
{
Sleep(50);
}
lock = true;
FileTail * temp = new FileTail[1];
if(this->currentFilePos >= fileSize)
{
lock = false;
temp->isOk = true;
return temp;
}
if(this->FPerGetLen + this->currentFilePos > fileSize)
{
temp->pos = ConvertIntToStr(this->currentFilePos);
temp->len = ConvertIntToStr(this->fileSize - this->currentFilePos);
temp->isOk = false;
this->currentFilePos = fileSize;
lock = false;
return temp;
}
temp->pos = ConvertIntToStr(this->currentFilePos);
temp->len = ConvertIntToStr(this->FPerGetLen);
temp->isOk = false;
this->currentFilePos = this->currentFilePos + this->FPerGetLen;
lock = false;
return temp;
}
String __fastcall TMultiFtp::ConvertIntToStr(DWORD len)
{
String str;
str = IntToStr(len);
int strLen;
strLen = str.Length();
for(int i =0 ; i < 10 -strLen ; i++)
{
str = "0"+str;
}
return str;
}
bool __fastcall TMultiFtp::ChangeDirectory(SOCKET client ,String dirName)
{
String dir = "CWD "+dirName+" \r\n";
this->DoOnTextOut(dir);
char *buffer = new char[100];
int rec
Kinonoyomeo
- 粉丝: 94
- 资源: 1万+
最新资源
- 神经网络 使用手写字数据集 实现分割任务 CNN
- 基于maxwell的4极6槽 内转子 11000rpm 输出转矩 156mNm 效率85% 180W 外径 48mm 内径27 轴向长度30mm 直流母线36V 永磁同步电机(永磁直流无刷)模型
- FPGA开发:SDRAM驱动代码,使用串口向sdram写数据,数据环回后被SDRAM送回到串口进行输出,中间使用FIFO进行跨时钟域处理,所用开发板DE2-115,SDRAM型号IS42S16320D
- ZTE C600&C620&C650命令参考
- python-workspace.zip.006
- FX5U FX40SSC 程序 FX5U FX 40SSC运动控制模块程序块 自己整合的针对FX 40SSC模块的功能块,支持点动故障码 状态码 相对定位 绝对定位 直接1指定轴号就可以
- 汽车二、三自由度模型 汽车二、三自由度模型 本人用了三种不同方法搭的汽车线性二自由度simulink模型,文档里包含有具体的车辆数值 适合初学者学习simulink使用(ps.模型输入为前轮转角,输出
- KUKA机器人码垛程序备份
- dbstudio-3.8.5.102.win64 神通数据库连接工具
- 开源TVBox影视盒子 小苹果影视盒子V1.5.7 2025新版
- 基于国产M0核MCU平台,全开源双电阻采样FOC高压 风机量产程序,包含龙博格电机观测器,SVPWM,顺逆风启动,五段式与七段式调制等源码,完全可以移植到别的MCU平台 适合电机算法研究
- 交替迭代法 matlab 无功优化 通过含固态变压器的无功优化算法,形成交替迭代潮流计算,最终计算出符合预期的电压曲线,程序方法包括包括牛拉法 前推回代等,参考性强
- 综合能源耦合微网优化程序matlab 程序基于冷热电联供综合能源耦合模型,采用cchp,并且含有压缩空气储能,采用粒子群优化求解
- DataGrip 2021.3 数据库连接工具
- 考虑碳交易的微网优化模型matlab
- FreeRTOS 是一款开源的、可抢占式的实时操作系统.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈