當前位置:首頁 » 文件管理 » ftpc函數

ftpc函數

發布時間: 2022-10-03 21:16:49

『壹』 c語言如何用ftpPutFile()函數上傳文件到Ftp伺服器!下載用FtpGetFile()可以!

  1. 先後使用InternetOpen和InternetConnect打開連接。
  2. 使用CreateFile函數打開本地文件。
  3. 使用FtpOpenFile函數打開遠程文件。
  4. 分別使用InternetReadFile和ReadFile函數讀取 FTP 或本地文件。
  5. 分別使用InternetWriteFile和WriteFile函數寫入 FTP 或本地文件。
  6. 使用CloseHandle函數關閉本地文件句柄。
  7. 使用InternetCloseHandle函數關閉 FTP 文件句柄。

『貳』 怎麼用cftpconnection類編寫向ftp server上傳文件

為了與FTP Internet伺服器通訊,必須先創建一個CInternetSession實例,然後創建CFtpConnection對象。創建CFtpConnection對象不採用直接方式,而是調用CInternetSession::GetFtpConnertion來創建並返回一個指向它的指針。

CFtpConnection類的成員

構造函數 CFtpConnection 構造一個CFtpConnection對象

操作 SetCurrentDirectory 設置當前FTP目錄

GetCurrentDirectory 獲取此次連接的當前目錄

GetCurrentDirectoryAsURL 獲取作為URL的此次連接的當前目錄

RemoveDirectory 從伺服器移去指定目錄

CreateDirectory 在伺服器上構造一個目錄

Rename 將伺服器上的文件改名

Remove 從伺服器上移去一個文件

PutFile 將一個文件放到伺服器上

GetFile 從連接的伺服器上獲取一個文件

OpenFile 在連接的伺服器上打開一個文件

Close 關閉與伺服器的連接

實例一:上傳文件
CString strAppName = AfxGetAppName();
CInternetSession* pSession = new CInternetSession(strAppName);
CFtpConnection* pConn = pSession->GetFtpConnection("
10.46.1.232","Anonymous","",21);
pConn->SetCurrentDirectory("test");
CString strLocfile,strRemotefile;
strLocfile="C:\\cmd.txt";
strRemotefile="cmd.txt";
pConn->PutFile(strLocfile,strRemotefile,FTP_TRANSFER_TYPE_ASCII);
pConn->Close();
return 0;
實例二:Ftp的打開文件操作函數:OpenFile

『叄』 vc 編程 CFtpConnection類的getfile函數問題 !

你可以在返回失敗後調用GetLastError看看返回哪個錯誤碼,然後去查下這個錯誤碼對應的錯誤原因是什麼,這樣大家也好大致定位錯誤原因。

『肆』 如何在unix下,c語言中實現ftp文件傳輸

nt FtpInit(char* Host,char* Account,char* Passwd)
{
short shPortNumber;
long lAddr;
char RecvBuf[1024];
char SendBuf[1024];
int RecvLen,SendLen;

shPortNumber=htons(21);
lAddr=inet_addr(Host);
memset(HostName,0,16);
memcpy(HostName,Host,strlen(Host));
hClient=socket(AF_INET,SOCK_STREAM,0);
if (hClient<0)
{
return -1;
}
if(setsockopt(hClient,SOL_SOCKET,SO_RCVTIMEO,(char *)&rcvtime,sizeof(int)))
{
close(hClient);
return -1;
}

if(setsockopt(hClient,SOL_SOCKET,SO_KEEPALIVE,(char *)&keepalive,sizeof(int)))
{
close(hClient);
return -1;
}
SockAddr.sin_family = AF_INET;
SockAddr.sin_addr.s_addr = lAddr;
SockAddr.sin_port = shPortNumber;

if (connect(hClient,(const struct sockaddr *)&SockAddr,sizeof(SockAddr))<0)
{
close(hClient);
return -1;
}

memset(RecvBuf,0,1024);
if((RecvLen=FtpMatchReceive(hClient,RecvBuf, "220 ",1024))<=0)
{
close(hClient);
return -1;
}
if(SendLen=GetFtpSendBuf("USER",Account,SendBuf,1024)<=0)
{
close(hClient);
return -1 ;
}
if(SendFTPCommand(hClient,SendBuf)!=331)
{
close(hClient);
return -1;
}
if(SendLen=GetFtpSendBuf("PASS",Passwd,SendBuf,1024)<=0)
{
close(hClient);
return -1 ;
}
if(SendFTPCommand(hClient,SendBuf)!=230)
{
close(hClient);
return -1;
}

}
int FtpGetFile(char * FileName)
{
int hListenSocket;
int hDataSocket;
int RetWriteFile;
int ReturnCode;
char RemoteFileName[256];
char RemoteFile[256];
char ExecCommand[256];
char * pcSubDir;

memset(RemoteFileName,0,256);
memset(RemoteFile,0,256);
memset(ExecCommand,0,256);

strcpy(RemoteFileName,FileName);
memcpy(ExecCommand,"CWD ",4);

pcSubDir=strrchr(RemoteFileName,'\\');
if (pcSubDir !=NULL)
{
strncat(ExecCommand,RemoteFileName,RemoteFileName-pcSubDir);
if(SendFTPCommand(hClient,ExecCommand)!=250)
{
close(hClient);
return -1;
}
strcpy(RemoteFile,pcSubDir);
}
else
{
strcpy(RemoteFile,RemoteFileName);
}

if((hListenSocket=CreatListenSocket(hClient))<0)
{
close(hClient);
return -1;
}
if(RequestDataConnection(hClient,hListenSocket)<0)
{
close(hClient);
return -1;
}
memset( ExecCommand,0,256);
memcpy( ExecCommand,"RETR ",5);
strcat( ExecCommand,RemoteFile);
printf("The FileName=%s\n",RemoteFile);
strcat( ExecCommand,"\r\n");

ReturnCode=SendFTPCommand(hClient,ExecCommand);
if(ReturnCode!=150)
{
close(hClient);
return -1;
}
if((hDataSocket=AcceptDataConnection(hListenSocket))<0)
{
close(hClient);
return -1;
}
if((RetWriteFile=WriteFile(hDataSocket,RemoteFile))<0)
{
close(hDataSocket);
close(hClient);
return -1;
}

}

『伍』 我用CFtpConnection類的成員函數在ftp伺服器上創建一個文件夾,可怎麼把文件上傳到這個創建的文件夾呢

和本地文件讀寫類似的

先以讀方式打開本地文件,再以寫方式打開FTP遠程文件,然後讀取本地文件至遠程文件。

關鍵代碼:

bOpen=m_CFile.Open(m_str_LocalFileName,CFile::modeRead);
m_pRemoteFile=m_pConnect->OpenFile(m_str_remoteFileName,GENERIC_WRITE);
while((dwRead=m_CFile.Read(pBuf,m_FileLenStep))>0)
{
m_pRemoteFile->Write(pBuf,dwRead);

m_CurUploadSize+=dwRead;
}

『陸』 你好,這個你解決了嗎C語言如何用FtpPutFile()函數上傳文件到Ftp伺服器!下載用FtpGetFile()可以!

先後使用InternetOpen和InternetConnect打開連接。使用CreateFile函數打開本地文件。使用FtpOpenFile函數打開遠程文件。分別使用InternetReadFile和ReadFile函數讀取
FTP
或本地文件。分別使用InternetWriteFile和WriteFile函數寫入
FTP
或本地文件。使用CloseHandle函數關閉本地文件句柄。使用InternetCloseHandle函數關閉
FTP
文件句柄。

『柒』 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)行為,必須與此伺服器建立適當的連接。

『捌』 在linux中如何用C語言實現FTP上傳

ftp協議還是比較麻煩的,FTP上傳一般用script實現,幾行就行。若用C寫,起碼4,5百行。

『玖』 一個FTP客戶端的C語言程序中的一個函數不懂

前四個位元組是這樣,比如「220 ProFTPD 1.3.2c Server (Debian) [10.10.55.203]」
前四個位元組就是220空格,這個代表了服務主機的返回碼
atoi那個把字元串轉成整型,n就=220了

『拾』 如何使用php中ftp函數上傳文件以及解決上傳文件失敗的方法

一、 ftp上傳圖片參數說明。
1 $source:本機圖片完整的路徑。(/a/b/c.jpg)
2 $des :上傳目標linux主機完整的路徑。
3 $ftp_server:ftp地址
4 $ftp_user_name:ftp用戶名
5 $ftp_user_pass: ftp密碼
6 $port:埠

二、如何使用php中ftp函數上傳文件的方法
例如:
本地地址為:/a/b/c.jpg
目標地址為:/d/a/b/c.jpg
2.1、linux主機上傳linux主機。
01 function ftpSendFile($source,$des,$ftp_server,$ftp_user_name,$ftp_user_pass,$port)
02 {
03 // 此步驟是在於上傳目錄與本機的目錄不一致轉換使用
04 $des = "/d" . $des;
05 $conn_id = ftp_connect($ftp_server, $port) or die("Couldn't connect to $ftp_server");
06 $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
07 ftp_pasv($conn_id, TRUE);
08 $ftp_folder = dirname($des);
09 $dir = explode("/", $ftp_folder);
10 $path = "";
11 for ($i = 0; $i < count($dir); $i++) {
12 $path .= "/" . $dir[$i];
13 if (!ftp_chdir($conn_id, $path)) {
14 $result = ftp_mkdir($conn_id, $path);
15 }
16 }
17 if (ftp_put($conn_id, $des, $source, FTP_BINARY)) {
18 return 1;
19 } else {
20 return 0;
21 }
22 ftp_close($conn_id);
23 }

2.2、windows主機上傳linux主機。
01 function sendPic($source,$des,$ftp_server,$ftp_user_name,$ftp_user_pass,$port)
02 {
03 $des = "/d" . $des;
04 $conn_id = ftp_connect($ftp_server, $port) or die("Couldn't connect to $ftp_server");
05 $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
06 ftp_pasv($conn_id, TRUE);
07 $ftp_folder = dirname(str_ireplace('\\', '/', $des));
08 $dir = explode("/", $ftp_folder);
09 $path = "";
10 for ($i = 0; $i < count($dir); $i++) {
11 $path .= "/" . $dir[$i];
12 if (!ftp_chdir($conn_id, $path)) {
13 $result = ftp_mkdir($conn_id, $path);
14 }
15 }
16 if (ftp_put($conn_id, str_ireplace('\\', '/', $des), $source, FTP_BINARY)) {
17 return 1;
18 } else {
19 return 0;
20 }
21 ftp_close($conn_id);
22 }

上面的兩種使用php中ftp函數上傳文件的方法基本可以滿足正常的使用。

熱點內容
賽爾編程 發布:2024-10-08 22:30:12 瀏覽:161
威馳車有哪些配置 發布:2024-10-08 22:19:32 瀏覽:564
手游源碼全套 發布:2024-10-08 21:39:41 瀏覽:474
大眾賬號密碼是多少 發布:2024-10-08 21:22:18 瀏覽:890
價格厚道香港多ip伺服器 發布:2024-10-08 21:22:16 瀏覽:283
android適配values 發布:2024-10-08 21:18:36 瀏覽:240
數控折彎機如何編程 發布:2024-10-08 20:34:40 瀏覽:62
pod內部修改配置如何生效 發布:2024-10-08 20:25:33 瀏覽:238
重慶伺服器託管市場低價雲主機 發布:2024-10-08 20:23:39 瀏覽:365
運維接觸源碼 發布:2024-10-08 19:55:44 瀏覽:486