❶ 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應該是大寫吧