Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

  • 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...