當前位置:首頁 » 文件管理 » vcftp文件上傳

vcftp文件上傳

發布時間: 2023-05-30 11:28:46

Ⅰ 如何使用ftp上傳文件

1、下載軟體FileZilla(用的比較多的一款),

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

Ⅲ VC6.0下,FTP文件上傳出錯,請問如何得到錯誤信息

首先,用
GetLastError
()
函數得到
錯誤代碼
,然後在網上找找解決方法;如果這樣不行的話,那就再用
InternetGetLastResponseInfo()
函數得到錯誤信息,兩者結合起來,一般就能解決問題了。

Ⅳ FTP 伺服器怎麼上傳文件

ftp伺服器上傳文件,用毀攔到的工具:8uftp,步驟如下:

  1. 打開8uftp。


注意事項:壓縮文件絕侍以加快上傳速度,上傳的纖宏胡時候選擇二進制防止丟包。

Ⅳ c# FTP上傳文件

C#ftp上傳,參考如下:
///<summary>
///上傳文件
///</summary>/
//<paramname="fileinfo">需要上傳的文件</param>
///<paramname="targetDir">目標路徑</param>
///<paramname="hostname">ftp地址</param>/
//<paramname="username">ftp用戶名</param>/
//<paramname="password">ftp密碼</param>
publicstaticvoidUploadFile(FileInfofileinfo,stringtargetDir,stringhostname,stringusername,stringpassword)
{//1.checktarget
stringtarget;
if(targetDir.Trim()=="")
{return;}
target=Guid.NewGuid().ToString();
//使用臨時文件名
森乎嫌stringURI="FTP://"+hostname+"/"+targetDir+"/"+target;
///WebClientwebcl=newWebClient();
System.Net.FtpWebRequestftp=GetRequest(URI,username,password);
//設置FTP命令設置所要執行的FTP命令,
//ftp.Method=System.Net.WebRequestMethods.Ftp.ListDirectoryDetails;//假設此處為顯示指定路徑下的文件列表
ftp.Method=System.Net.WebRequestMethods.Ftp.UploadFile;
//指定文件傳輸的數據類型
ftp.UseBinary=true;
ftp.UsePassive=true;//告訴ftp文件大小
ftp.ContentLength=fileinfo.Length;
//緩沖大小設置為2KB
constintBufferSize=2048;
byte[]content=newbyte[BufferSize-1+1];
intdataRead;//打開一個文件流(System.IO.FileStream)去讀上傳的文件
using(FileStreamfs=fileinfo.OpenRead())
{
try{//把上頃橡傳的文件寫入流
using(Streamrs=ftp.GetRequestStream())
{do
{//每次讀文件流的2KB
dataRead=fs.Read(content,0,BufferSize);rs.Write(content,0,dataRead);}
while(!(dataRead<BufferSize));rs.Close();}}
catch(Exceptionex){}finally{fs.Close();}}
ftp=null;//設置FTP命令
ftp=GetRequest(URI,username,password);
ftp.Method=System.Net.WebRequestMethods.Ftp.Rename;//改名
ftp.RenameTo=此手fileinfo.Name;try{ftp.GetResponse();}
catch(Exceptionex)
{
ftp=GetRequest(URI,username,password);ftp.Method=System.Net.WebRequestMethods.Ftp.DeleteFile;//刪除
ftp.GetResponse();throwex;}finally
{
//fileinfo.Delete();}//可以記錄一個日誌"上傳"+fileinfo.FullName+"上傳到"+"FTP://"+hostname+"/"+targetDir+"/"+fileinfo.Name+"成功.");
ftp=null;
#region
/******FtpWebResponse*****///FtpWebResponseftpWebResponse=(FtpWebResponse)ftp.GetResponse();
#endregion
}
///<summary>
///下載文件
///</summary>
///<paramname="localDir">下載至本地路徑</param>
///<paramname="FtpDir">ftp目標文件路徑</param>
///<paramname="FtpFile">從ftp要下載的文件名</param>
///<paramname="hostname">ftp地址即IP</param>
///<paramname="username">ftp用戶名</param>
///<paramname="password">ftp密碼</param>
publicstaticvoidDownloadFile(stringlocalDir,stringFtpDir,stringFtpFile,stringhostname,stringusername,stringpassword)
{
stringURI="FTP://"+hostname+"/"+FtpDir+"/"+FtpFile;
stringtmpname=Guid.NewGuid().ToString();
stringlocalfile=localDir+@""+tmpname;

System.Net.FtpWebRequestftp=GetRequest(URI,username,password);
ftp.Method=System.Net.WebRequestMethods.Ftp.DownloadFile;
ftp.UseBinary=true;
ftp.UsePassive=false;

using(FtpWebResponseresponse=(FtpWebResponse)ftp.GetResponse())
{
using(StreamresponseStream=response.GetResponseStream())
{
//looptoread&writetofile
using(FileStreamfs=newFileStream(localfile,FileMode.CreateNew))
{
try
{
byte[]buffer=newbyte[2048];
intread=0;
do
{
read=responseStream.Read(buffer,0,buffer.Length);
fs.Write(buffer,0,read);
}while(!(read==0));
responseStream.Close();
fs.Flush();
fs.Close();
}
catch(Exception)
{
//
fs.Close();
//deletetargetfileasit'sincomplete
File.Delete(localfile);
throw;
}
}

responseStream.Close();
}

response.Close();
}try
{
File.Delete(localDir+@""+FtpFile);
File.Move(localfile,localDir+@""+FtpFile);


ftp=null;
ftp=GetRequest(URI,username,password);
ftp.Method=System.Net.WebRequestMethods.Ftp.DeleteFile;
ftp.GetResponse();

}
catch(Exceptionex)
{
File.Delete(localfile);
throwex;
}

//記錄日誌"從"+URI.ToString()+"下載到"+localDir+@""+FtpFile+"成功.");
ftp=null;
}

///<summary>
///搜索遠程文件
///</summary>
///<paramname="targetDir"></param>
///<paramname="hostname"></param>
///<paramname="username"></param>
///<paramname="password"></param>
///<paramname="SearchPattern"></param>
///<returns></returns>
publicstaticList<string>ListDirectory(stringtargetDir,stringhostname,stringusername,stringpassword,stringSearchPattern)
{
List<string>result=newList<string>();
try
{
stringURI="FTP://"+hostname+"/"+targetDir+"/"+SearchPattern;

System.Net.FtpWebRequestftp=GetRequest(URI,username,password);
ftp.Method=System.Net.WebRequestMethods.Ftp.ListDirectory;
ftp.UsePassive=true;
ftp.UseBinary=true;


stringstr=GetStringResponse(ftp);
str=str.Replace(" "," ").TrimEnd(' ');
str=str.Replace(" "," ");
if(str!=string.Empty)
result.AddRange(str.Split(' '));

returnresult;
}
catch{}
returnnull;
}

(FtpWebRequestftp)
{
//Gettheresult,streamingtoastring
stringresult="";
using(FtpWebResponseresponse=(FtpWebResponse)ftp.GetResponse())
{
longsize=response.ContentLength;
using(Streamdatastream=response.GetResponseStream())
{
using(StreamReadersr=newStreamReader(datastream,System.Text.Encoding.Default))
{
result=sr.ReadToEnd();
sr.Close();
}

datastream.Close();
}

response.Close();
}

returnresult;
}
///在ftp伺服器上創建目錄
///</summary>
///<paramname="dirName">創建的目錄名稱</param>
///<paramname="ftpHostIP">ftp地址</param>
///<paramname="username">用戶名</param>
///<paramname="password">密碼</param>
publicvoidMakeDir(stringdirName,stringftpHostIP,stringusername,stringpassword)
{
try
{
stringuri="ftp://"+ftpHostIP+"/"+dirName;
System.Net.FtpWebRequestftp=GetRequest(uri,username,password);
ftp.Method=WebRequestMethods.Ftp.MakeDirectory;

FtpWebResponseresponse=(FtpWebResponse)ftp.GetResponse();
response.Close();
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message);
}
}
///<summary>
///刪除目錄
///</summary>
///<paramname="dirName">創建的目錄名稱</param>
///<paramname="ftpHostIP">ftp地址</param>
///<paramname="username">用戶名</param>
///<paramname="password">密碼</param>
publicvoiddelDir(stringdirName,stringftpHostIP,stringusername,stringpassword)
{
try
{
stringuri="ftp://"+ftpHostIP+"/"+dirName;
System.Net.FtpWebRequestftp=GetRequest(uri,username,password);
ftp.Method=WebRequestMethods.Ftp.RemoveDirectory;
FtpWebResponseresponse=(FtpWebResponse)ftp.GetResponse();
response.Close();
}
catch(Exceptionex)
{

MessageBox.Show(ex.Message);
}
}
///<summary>
///文件重命名
///</summary>
///<paramname="currentFilename">當前目錄名稱</param>
///<paramname="newFilename">重命名目錄名稱</param>
///<paramname="ftpServerIP">ftp地址</param>
///<paramname="username">用戶名</param>
///<paramname="password">密碼</param>
publicvoidRename(stringcurrentFilename,stringnewFilename,stringftpServerIP,stringusername,stringpassword)
{
try
{

FileInfofileInf=newFileInfo(currentFilename);
stringuri="ftp://"+ftpServerIP+"/"+fileInf.Name;
System.Net.FtpWebRequestftp=GetRequest(uri,username,password);
ftp.Method=WebRequestMethods.Ftp.Rename;

ftp.RenameTo=newFilename;
FtpWebResponseresponse=(FtpWebResponse)ftp.GetResponse();

response.Close();
}
catch(Exceptionex){MessageBox.Show(ex.Message);}}
(stringURI,stringusername,stringpassword)
{
//根據伺服器信息FtpWebRequest創建類的對象
FtpWebRequestresult=(FtpWebRequest)FtpWebRequest.Create(URI);
//提供身份驗證信息
result.Credentials=newSystem.Net.NetworkCredential(username,password);
//設置請求完成之後是否保持到FTP伺服器的控制連接,默認值為true
result.KeepAlive=false;
returnresult;
}

Ⅵ 怎麼用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

Ⅶ 如何用C++實現FTP文件上傳的程序

給你個例子
#include <afxinet.h>
void main()
{
BOOL dRes,pRes;
HINTERNET hInternet;
HINTERNET hConnect;
hInternet = InternetOpen("A3GS Sample", INTERNET_OPEN_TYPE_DIRECT,
NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE);
if ( NULL == hInternet )
{
printf("InternetOpen Error:%d\n", GetLastError() );
}
hConnect = InternetConnect(hInternet, "洞歷散127.0.0.1", INTERNET_DEFAULT_FTP_PORT,
"ww123", "12345", INTERNET_SERVICE_FTP,
INTERNET_FLAG_EXISTING_CONNECT || INTERNET_FLAG_PASSIVE,0 );
if ( NULL == hInternet )
{
printf( "InternetConnect Error:%d\n", GetLastError() );
InternetCloseHandle(hInternet);
}

dRes = FtpGetFile(hConnect, "./wwyy/download/test1.txt", "D:\\BT\\test1.txt", FALSE,
FILE_ATTRIBUTE_ARCHIVE, FTP_TRANSFER_TYPE_UNKNOWN, 0);
if ( dRes == 0 )
{
printf( "FtpGetFile Error:\n", GetLastError() );
}else{
printf( "下載文件成納氏功!\n" );
}
pRes = FtpPutFile(hConnect,"D:\\BT\\hhsj.txt","hhsj.txt",FTP_TRANSFER_TYPE_ASCII,0);
if(pRes==0)
{
printf("上傳文件失敗!\n");
}else{
printf("上傳文件爛數成功!\n");
}
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
if(dRes&&pRes) return true;
else return false;

Ⅷ ftp命令怎麼上傳文件夾

1、輸入命令行:--> FTP 10.1.61.212 如果對方沒有開啟FTP服務,那麼這個命令就不會有效果。

Ⅸ ftp 怎樣上傳

FTP上傳是通過ftp協議把文件從本地電腦和遠程伺服器傳輸的過程,包括上傳和下載的過程。

文件類型很多了,任何文件都可以上傳下載。

你可以在伺服器端部署ftp服務端程序,給對方開一個新的ftp賬號,把ip和賬號信息告訴對方,他就可以用來上傳文件了。

和別人共用伺服器時採用這種方法,可以把對方的許可權限制在某個文件夾裡面,他只能在這里上傳下載文件,對於伺服器安全、許可權都有保障。

Ⅹ ftp怎麼設置上傳文件

其功能比較復雜,這里只就文件上傳設定的方式作個說明。
[語法] upload [absolute|relative] [class=]... [-]
["dirs"|"nodirs"] []
[說明] 定義這個目錄是允許或拒絕上傳。假如允許上傳的話,則所有的文件是及所擁有,而且其文件許可權是。
例如:upload /var/ftp * no
upload /var/ftp /incoming yes ftp daemon 0666
upload /var/ftp /incoming/gifs yes jlc guest 0600 nodirs
上面的設置只允許文件上傳到/incoming及/incomeing/gifs這二個目錄,被上傳到/incoming的文件其所有權將是ftp/daemon,而其許可權是0666;被上傳到/incoming/gifs的文件,其所有權將是jlc/guest,而其許可權是0600。注意是指ftp目錄;必須跟系統密碼文件內 (/etc/passwd) 的使用者目錄一致。
此外,dirs及nodirs這二個選項可有可無。這二個選項是指:允許(dirs)或不允許(nodirs)使用mkdir這個指令來產生新的子目錄。
注意,假如不指明的話,「產生新的子目錄」這個許可權是默認是被允許的。
這個選項決定新產生子目錄的許可權。假如被省略,則目錄許可權將會是;若是也沒有的話,則新產生子目錄的許可權將是777。
注意,上傳這個功能只對"用戶主目錄" (或使用者的根目錄?) 在底下的使用者有效。假如把設為"*"的話,則不受此限制。更進一步說明,就是指chroot()這個指令的輸入參數。 及也可以設定成"*"。在這個情況下,任何上傳的文件及新產生子目錄的所有權將被設置成與其所在的上層目錄所有權一致。
[absolute|relative]
這個選項可有可無。這個選項定義這個目錄將被解釋為絕對路徑 (absolute),或是目前chroot環境的相對路徑 (relative)。預設是絕對路徑 (absolute)。
這個選項一定要有。yes是指允許上傳,反之則禁止

熱點內容
ps資料庫 發布:2024-04-20 19:52:43 瀏覽:521
dpi的演算法 發布:2024-04-20 19:41:16 瀏覽:933
成興ca鎖密碼初始密碼是什麼 發布:2024-04-20 19:24:43 瀏覽:667
如何更准確的看手機配置 發布:2024-04-20 19:15:12 瀏覽:332
匯優的演算法 發布:2024-04-20 19:10:51 瀏覽:414
和平精英暗夜危機模式密碼是什麼 發布:2024-04-20 19:10:03 瀏覽:686
韓國泡泡安卓怎麼充值 發布:2024-04-20 18:56:27 瀏覽:295
電腦極速緩存怎麼打開 發布:2024-04-20 18:55:43 瀏覽:143
哈弗h9有哪些高科技配置 發布:2024-04-20 18:51:29 瀏覽:773
平板的數字密碼在哪裡設置 發布:2024-04-20 18:39:13 瀏覽:972