Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

c# - Difference between FTP/FTPS/SFTP - Configurable connection to any of them

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").

I am fresh to these protocols, having so many doubts.

  1. What is the difference between FTP and SFTP server?
  2. Is it possible to access FTP server using SFTP connection methods and vice versa (guided to use Rebex library to connect to SFTP)?
  3. How can change following FTP upload method to FTPS

Code is below:

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(); 

Is it like changing url from FTP to FTPS?

string uploadUrl = String.Format("ftps://{0}/{1}", ftpurl, PureFileName);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  • FTP: the old file transfer protocol (RFC959). Problematic with firewalls since it is using dynamic ports and the information about these ports gets exchanged at the application level.
  • FTPS: the old FTP protocol but support for TLS added. Even more problematic with firewalls since these can no longer look into the application level to find out which ports are used.
  • SFTP: something completely different, because it uses the SSH protocol to transfer files. No problems with firewalls.

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.

As for using FTPS with FtpWebRequests see msdn. Using SFTP with FtpWebRequests is not possible but there are other libraries.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...