問題描述
我有一個(gè)要求,例如需要?jiǎng)?chuàng)建一個(gè) C# 應(yīng)用程序,該應(yīng)用程序?qū)⒏鶕?jù) app.config
文件中輸入的設(shè)置將 excel 文件上傳到FTP/SFTP"服務(wù)器(使用ftpftpssftp").
I have a requirement like need to create a C# app which will upload an excel file to "FTP/SFTP" server based on settings entered on the app.config
file (using "ftpftpssftp").
我對(duì)這些協(xié)議很陌生,有很多疑問.
I am fresh to these protocols, having so many doubts.
- FTP 和 SFTP 服務(wù)器有什么區(qū)別?
- 是否可以使用 SFTP 連接方式訪問 FTP 服務(wù)器,反之亦然(指導(dǎo)使用 Rebex 庫(kù)連接 SFTP)?
- 如何將以下 FTP 上傳方式更改為 FTPS
代碼如下:
string PureFileName = new FileInfo(fileName).Name;
string uploadUrl = String.Format("ftp://{0}/{1}", ftpurl, PureFileName);
FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(uploadUrl);
req.Proxy = null;
req.Method = WebRequestMethods.Ftp.UploadFile;
req.Credentials = new NetworkCredential(user, pass);
req.UseBinary = true;
req.UsePassive = true;
byte[] data = File.ReadAllBytes(fileName);
req.ContentLength = data.Length;
Stream stream = req.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
FtpWebResponse res = (FtpWebResponse)req.GetResponse();
是否像將 url
從 FTP 更改為 FTPS?
Is it like changing url
from FTP to FTPS?
string uploadUrl = String.Format("ftps://{0}/{1}", ftpurl, PureFileName);
推薦答案
- FTP:舊的文件傳輸協(xié)議 (RFC959).防火墻存在問題,因?yàn)樗褂脛?dòng)態(tài)端口,并且有關(guān)這些端口的信息在應(yīng)用程序級(jí)別進(jìn)行交換.
- FTPS:舊的 FTP 協(xié)議,但增加了對(duì) TLS 的支持.防火墻的問題更嚴(yán)重,因?yàn)樗鼈儫o(wú)法再查看應(yīng)用程序級(jí)別來(lái)找出使用了哪些端口.
- SFTP:完全不同的東西,因?yàn)樗褂?SSH 協(xié)議來(lái)傳輸文件.防火墻沒有問題.
如果您的代碼能夠處理 FTPS,那么它通常也能夠處理 FTP,但是有很多代碼只能處理 FTP 而不能處理 FTPS.由于 SFTP 是一種完全不同的協(xié)議代碼,處理 FTP/FTPS 通常無(wú)法進(jìn)行 SFTP.而 SFTP 處理代碼不會(huì)做 FTP/FTPS.也有例外,即 FileZilla 可以在單個(gè)應(yīng)用程序中處理所有這些協(xié)議.
If your code is able to handle FTPS it is usually able to handle FTP too, but there is lots of code which can only handle FTP and not FTPS. Since SFTP is a completely different protocol code handling FTP/FTPS will usually not be able to do SFTP. And SFTP handling code will not do FTP/FTPS. There are exceptions, i.e. FileZilla can handle all these protocols in a single application.
關(guān)于將 FTPS 與 FtpWebRequests 一起使用,請(qǐng)參閱 msdn.無(wú)法將 SFTP 與 FtpWebRequests 一起使用,但有其他庫(kù).
As for using FTPS with FtpWebRequests see msdn. Using SFTP with FtpWebRequests is not possible but there are other libraries.
這篇關(guān)于FTP/FTPS/SFTP之間的區(qū)別 - 可配置連接到它們中的任何一個(gè)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!