The difference between FTP / FTPS / SFTP is a custom connection to any of them.

I have a requirement, since you need to create a C # application that will output the excel file to the FTP / SFTP server based on the settings entered in the file app.config(using "ftp \ ftps \ sftp").

I am familiar with these protocols, having so many doubts.

  • What is the difference between FTP and SFTP server?
  • Is it possible to access the FTP server using SFTP connection methods and vice versa (it is recommended to use the Rebex library to connect to SFTP)?
  • How to change FTP upload method in FTPS

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

How to change urlfrom FTP to FTPS?

string uploadUrl = String.Format("ftps://{0}/{1}", ftpurl, PureFileName);
+4
source share
4 answers
  • FTP: (RFC959). , , .
  • FTPS: FTP, TLS. , , , .
  • SFTP: - , SSH . .

FTPS, FTP , , FTP, FTPS. SFTP - , FTP/FTPS, , SFTP. SFTP FTP/FTPS. , FileZilla .

FTPS FtpWebRequests, . msdn. SFTP FtpWebRequests , .

+6

SFTP FTP/FTPS - . FTP SFTP- . FTPS - FTP TLS/SSL. FTP-/ FTPS.

FTP (S) .NET ( FtpWebRequest). FTPS, URL- ftps:// FtpWebRequest.EnableSsl true.

.NET SFTP. SFTP.


, .

, WinSCP.NET () SessionOptions.Protocol Protocol.FTP Protocol.SFTP.

SFTP:

SessionOptions sessionOptions = new SessionOptions {
    Protocol = Protocol.Sftp,
    HostName = "example.com",
    UserName = "user",
    Password = "mypassword",
    SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
};

Session session = new Session();
session.Open(sessionOptions);

FTP:

SessionOptions sessionOptions = new SessionOptions {
    Protocol = Protocol.Ftp,
    HostName = "example.com",
    UserName = "user",
    Password = "mypassword",
};

Session session = new Session();
session.Open(sessionOptions);

FTPS:

SessionOptions sessionOptions = new SessionOptions {
    Protocol = Protocol.Ftp,
    FtpSecure = FtpSecure.Explicit,
    HostName = "example.com",
    UserName = "user",
    Password = "mypassword",
};

Session session = new Session();
session.Open(sessionOptions);

, , SessionOptions.ParseUrl , (URL), .

SessionOptions sessionOptions = new SessionOptions();
sessionOptions.ParseUrl(connectionString);

Session session = new Session();
session.Open(sessionOptions);

:

  • SFTP: sftp://user@mypassword;fingerprint=ssh-rsa-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx@example.com
  • FTP: ftp://user@mypassword@example.com
  • FTPS: ftpes://user@mypassword@example.com

WinSCP (GUI) URL ( ) .


, WinSCP.NET .NET. .NET (WinSCP).

.NET, . .

( WinSCP)

+5
  • , . FTP SFTP - . FTPS - FTP

  • WebRequestMethods.Ftp.UploadFile;, SFTP, , FTPS, - .

+1

FTPS Explicit

  // Setup session options
            SessionOptions sessionOptions = new SessionOptions
            {
                Protocol = Protocol.Ftp,
                HostName = "address.co.za",
                FtpSecure = FtpSecure.Explicit,
                UserName = "username",
                Password = "pass",
                TlsHostCertificateFingerprint = "xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
            };

,

0

Source: https://habr.com/ru/post/1611151/


All Articles