❶ windows环境下c语言支持ftp和http多线程下载的客户端
下面的程序,编译之后,你可以运行很多个实例,目前我将文件写在了D:\1.txt,每个程序写1000行数据,这些值你可以自己更改(比如 写在C:,每个程序写10000行等),等程序都写完后,你可以去文件中查看写文件的结果。补充一下,我是在VC6.0环境中写的,所以windows.h,如果你不是在这个环境中的话,可能需要修改一些定义,比如DWORD等。其他的API都是windows平台提供的API;
#include <stdio.h>
#include "windows.h"
int main()
{
//获取进程ID,因为你希望是多个进程运行同时写一个文件,所以,我们打印出进程ID
DWORD dwProcessID = GetCurrentProcessId();
//初始化我们要写入文件中的内容,及该内容长度;
char szContent[100] = ;
sprintf(szContent,"process[%u] write file\r\n",dwProcessID);
DWORD dwContentLen = strlen(szContent);
//创建互斥量,这样可以进行进程间的互斥,当然用这个也可以做线程间的互斥
HANDLE hMutex = CreateMutex(NULL,FALSE,"MyFileMutex");
if (NULL == hMutex)
{
printf("[%u]Create/Open Mutex error!\r\n",dwProcessID);
return 1;
}
//创建或打开文件
HANDLE hFile = CreateFile("D:\\1.txt",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_WRITE | FILE_SHARE_READ,NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_ARCHIVE,
NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
printf("[%u]Creat/Open file error!\r\n",dwProcessID);
return 1;
}
//循环写入文件
for(int i = 0; i < 1000 ; i++)
{
//等待临界资源,即锁定文件
WaitForSingleObject(hMutex,INFINITE);
printf("Process[%u] Get the signal\r\n",dwProcessID);
DWORD len = 0;
//因为是共享写文件,即多个程序写一个文件,所以一定要将文件指针偏移到尾部
SetFilePointer(hFile,0,NULL,FILE_END);
//写入文件
BOOL rnt = WriteFile(hFile,szContent,dwContentLen,&len,NULL);
if (rnt == FALSE)
{
printf("Process[%u] Fail to write file\r\n",dwProcessID);
}
//释放互斥量,解除锁定
ReleaseMutex(hMutex);
//加个Sleep便于我们中间观察结果
Sleep(30);
}
CloseHandle(hMutex);
CloseHandle(hFile);
return 0;
}
应你要求,我把AIP中的宏定义解释如下:
HANDLE hFile = CreateFile("D:\\1.txt",
GENERIC_READ | GENERIC_WRITE,//表示程序对该文件有读和写的权限
FILE_SHARE_WRITE | FILE_SHARE_READ,//表示可以多个程序共享读和写的权限
NULL,
OPEN_ALWAYS,//表示打开该文件,如果该文件不存在,则创建该文件
FILE_ATTRIBUTE_ARCHIVE,//文件的属性为存档
NULL);
WaitForSingleObject(hMutex,INFINITE);
//INFINITE表示永远等待,直到hMutex有信号为止
SetFilePointer(hFile,0,NULL,FILE_END);
//FILE_END表示从文件尾部开始偏移;实际此举就是将文件指针偏移到文件尾部;
另外,虚机团上产品团购,超级便宜
❷ C语言如何连接FTP,连接成功后遍历FTP下目录,包括子目录,要源代码,而且是成功案例,自以为是的靠边站!
用libcurl实现,具体代码看
http://curl.haxx.se/libcurl/c/ftpget.html
❸ 多线程FTP程序用VC/C++如何设计
这是codeproject的关于ftp的实现,你可以去down源代码
Introction
StuffFTP is a free for life FTP client. This FTP client will allow you to connect to FTP servers and upload and download files.
Motivation
Why did I create and continue to support StuffFTP? First it is a learning experience, and since I just got laid off from my company, I decided to use some of the tools they have provided, its legal as I technically bought them and they do not have other programmers following in my footstep nor do they plan on hiring any, to create something for the community. I also used another FTP program that was freeware for a while and then became pay to use software with little to no notice. That irked me and a friend suggested I create my own FTP client. So I am.
Progress
This is currently a work in progress and I would be the first to say there is a lot of work to do. Since I am laid off, I have lots of time on my hands. And this is an excellent chance for me to learn some of the concepts of C++ that I wanted to, but never had the chance while I was working. I was hoping to get a job in San Jose, CA, but decided to hold off and live on saving for a while.
Guarantee
I will support this program as best as I can. I have already setup a website and forum for it, here. I use the forum because I have trouble responding to email especially when I get a whole bunch of SPAM everyday. There is no adware or spyware in the program, and I guarantee that it will be free for the life of the program.
Some people have already asked why I don't open source the project. The main reason is I do not know if I can. StuffFTP uses some proprietary third party libraries. I do not know if I can post the source code or header files to those libraries. So everyone will have to wait until I can get rid of those libraries or hear back from the companies concerning my question about releasing header and associated help files.
Tools
* MS Windows XP Professional
* MS Visual Studio .NET C++/MFC
* Clickteam Install Maker
* Clickteam Patch Maker
* Betaone.net forum members
* CXListCtrl by Hans Dietrich
3rd Party Libraries
The application uses Catalyst Socket Tools Library Edition and Professional UI GUI library. So far the support has been fair with Prof-UI and outstanding with Catalyst. The Catalyst tool is for the actual FTP connection and, as the name suggests, Prof-UI is being used for the GUI.
Updates
You can find the latest updates here and you can also find my latest ramblings, blogs, and support here. This is where you can find out all the latest versions and information.
How to contribute
Money! Just kidding you can contribute by downloading, using, and giving feedback on the program. That way I can determine which path to take with the application and which features to prioritize or not. Graphics is also where I need lots of help. I am left brained and can not draw a good stick figure to save my life. If you can help with graphics or anything else, please let me know. Also talk to me, I am bored. I have no job at the moment so I can use the company.
Features
* Able to upload/download from server/computer
* Connect to FTP sites using login
* Connect using other ports besides 21
* Delete, rename, and CHMOD a file
History
* 12/10/2003 - Version 0.11a
* 12/07/2003 - Version 0.10a
❹ 想用C++实现FTP功能:选定自己电脑上的txt文件,发送到用网线连接的另一台电脑上。很急,求大神支招
可以参考下面代码
CInternetSessionsession("MyFtpsession");
CFtpConnection*pconn;
pconn=NULL;
inttrycount=0;
CString搭搭UpFile;
UpFile="c:\a.rar";
CStringFtpIP,FtpUserName,FtpPassword,FtpDir;
FtpIP="192.168.1.100";
FtpUserName="userup";
FtpPassword="uppass";
FtpDir="/";
unsignedshortport;
port=21;
reconn:
try
{
pconn=session.GetFtpConnection(FtpIP,
FtpUserName,FtpPassword,port,FALSE);//INTERNET_INVALID_PORT_NUMBER,FALSE);
}
catch(CInternetException*pException)
{
trycount++;
if(trycount==2)
{
pException->ReportError();
returnFALSE;
}
else
{
//srand((unsigned)time(0));//设种子
//Delay((long)rand()*10000);
goto知轿拿reconn;
}
}
if(!pconn->SetCurrentDirectory(FtpDir))
{
TRACE("SetDirError");
returnFALSE;
}
if(!(pconn->PutFile(UpFile,FTP_TRANSFER_TYPE_BINARY,1)))
{
return帆瞎FALSE;
TRACE("PutError");
}
session.Close();
deletepconn;
deletesession;
pconn=NULL;
❺ C语言实现从FTP下载、上传文件
FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议”。
1.C语言可以使用CStdioFile函数打开本地文件。使用类CInternetSession 创建并初始化一个Internet打开FTP服务器文件。
CStdioFile继承自CFile,一个CStdioFile 对象代表一个用运行时函数fopen 打开的C 运行时流式文件。
流式文件是被缓冲的,而且可以以文本方式(缺省)或二进制方式打开。文本方式提供对硬回车—换行符对的特殊处理。当你将一个换行符(0x0A)写入一个文本方式的CStdioFile 对象时,字节对(0x0D,0x0A)被发送给该文件。当你读一个文件时,字节对(0x0D,0x0A)被翻译为一个字节(0x0A)。
CStdioFile 不支持Duplicate,LockRange,和UnlockRange 这几个CFile 函数。如果在CStdioFile 中调用了这几个函数,将会出现CNoSupported 异常。
使用类CInternetSession 创建并初始化一个或多个同时的Internet 会话。如果需要,还可描述与代理服务器的连接。
如果Internet连接必须在应用过程中保持着,可创建一个类CWinApp的CInternetSession成员。一旦已建立起Internet 会话,就可调用OpenURL。CInternetSession会通过调用全局函数AfxParseURL来为分析映射URL。无论协议类型如何,CInternetSession 解释URL并管理它。它可处理由URL资源“file://”标志的本地文件的请求。如果传给它的名字是本地文件,OpenURL 将返回一个指向CStdioFile对象的指针。
如果使用OpenURL在Internet服务器上打开一个URL,你可从此处读取信息。如果要执行定位在服务器上的指定的服务(例如,HTTP,FTP或Gopher)行为,必须与此服务器建立适当的连接。
❻ 如何设置多线程FTP下载
FlashfXP只能单线程下载,可以先用FlashfXP登录FTP站点,选中你要下载的文件,右击鼠标,在出现的菜单上选择:“复制URL(Ctrl+U)”,FlashfXP会提示:“是否复制用户名及密码?”,选择“是”,然后打开迅雷,点“新建(Ctrl+N)”下载任务,在出现的界面上边:“网址(URL)”里面(Ctrl+V)填上刚刚粘贴的信息,这样迅雷就可以从你的FTP站点多线程下载文件了,而且你可以同时下载不同的文件,也是多线程的。当然,万一你的FTP站点是限制单线程下载的话,为了充分利用带宽,就只好同时下载其他文件来提高效率。万一你的FTP站点是限制每个IP只能单线程下载一份文件,这个办法可能就无能为力了。希望能帮到你,呵呵~~
❼ ftp不支持多线程同时下载操作
ftp支持多线程同时下载操作。因为ftp支持多线程同时下载操作需要自己设计,在功能菜单中选择“站点属性”,接着取消属性窗口中的“没有限制”选项并填入下载线程数目即可。所以ftp支持多线程同时下载操作。
❽ C#多线程ftp下载的实现(java也可,关键是思路)
参考答案:读书之法,在循序而渐进,熟读而精思。——朱熹
❾ VC++编写连接FTP服务器程序,编译的时候报错
m_pInetsession=new CInternetsession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
这一行 中的 CInternetSession中的session应该是大写吧