The company requires that the FTP interface cannot be transmitted in clear text, so the ADC system will increase the FTPS mode, but there are many ways to find the network can not be achieved
Used a
Method One
FtpWebRequest request = (ftpwebrequest) webrequest.create (Fileuploadpath);
Request. Method = WebRequestMethods.Ftp.ListDirectory;
Request. Credentials = new NetworkCredential (UPLOADUSER,UPLOADPWD);
Request. Enablessl = true;
Request. Usepassive = true;
Servicepointmanager.servercertificatevalidationcallback = Delegate (object sender, X509Certificate certificate, X509chain chain, Sslpolicyerrors sslpolicyerrors)
{return true;};
FtpWebResponse response = (ftpwebresponse) request. GetResponse ();
Stream responsestream = null;
StreamReader readstream = null;
Try
{
Responsestream = Response. GetResponseStream ();
Readstream = new StreamReader (Responsestream, System.Text.Encoding.UTF8);
if (readstream! = null)
Console.WriteLine (Readstream.readtoend ());
}
Finally
{
if (readstream! = null)
Readstream.close ();
if (response! = NULL)
Response. Close ();
}
Method Two
public void Upload (string filename)
{
FileInfo Fileinf = new FileInfo (filename);
String uri = "ftp://" + Ftpserverip + "/" + fileinf.name;
FtpWebRequest reqftp;
To create a FtpWebRequest object from a URI
Reqftp = (ftpwebrequest) ftpwebrequest.create (New Uri ("ftp://" + Ftpserverip + "/" + Fileinf.name));
FTP User name and password
Reqftp.credentials = new NetworkCredential (Ftpuserid, FTPPassword);
Ssl
Reqftp.enablessl = true;
The default is true and the connection is not closed
is executed after a command
Reqftp.keepalive = false;
Specify what commands to execute
Reqftp.method = WebRequestMethods.Ftp.UploadFile;
Specifying data Transfer Types
Reqftp.usebinary = true;
Specify transfer Mode
Reqftp.usepassive =false;
Notifies server file size when uploading a file
Reqftp.contentlength = Fileinf.length;
Buffer size set to 2KB
int bufflength = 2048;
byte[] buff = new Byte[bufflength];
int Contentlen;
Open a file stream (System.IO.FileStream) to read the uploaded file
FileStream fs = Fileinf.openread ();
Try
{
Write the uploaded file to the stream
Stream strm = Reqftp.getrequeststream ();
2KB per read file stream
Contentlen = fs. Read (Buff, 0, bufflength);
Stream content does not end
while (Contentlen! = 0)
{
Write content from file stream to upload stream
Strm. Write (Buff, 0, Contentlen);
Contentlen = fs. Read (Buff, 0, bufflength);
}
Close two streams
Strm. Close ();
Fs. Close ();
}
catch (Exception ex)
{
MessageBox.Show (ex. Message, "Upload Error");
}
}
It's all about the remote link failure. Also mention that our server is not required to verify the port number of the certificate is 9,901 fixed if the passive mode to log on
Can you please help me see what improvements or direct cases to provide
FTPs encrypted uploads