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.
- What is the difference between FTP and SFTP server?
- Is it possible to access FTP server using SFTP connection methods and vice versa (guided to use Rebex library to connect to SFTP)?
- 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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…