csharp Enviar un fichero来自FTP usando C#para .NET

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Enviar un fichero来自FTP usando C#para .NET相关的知识,希望对你有一定的参考价值。

string ftpServerIP = "ftp.example.com";
string ftpUserName = "username";
string ftpPassword = "password";
string filename = Server.MapPath("example.txt");
		
FileInfo objFile = new FileInfo(filename);

FtpWebRequest objFTPRequest;

// Create FtpWebRequest object 
objFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + objFile.Name));

// Set Credintials
objFTPRequest.Credentials = new NetworkCredential(ftpUserName, ftpPassword);

// By default KeepAlive is true, where the control connection is 
// not closed after a command is executed.
objFTPRequest.KeepAlive = false;

// Set the data transfer type.
objFTPRequest.UseBinary = true;

// Set content length
objFTPRequest.ContentLength = objFile.Length;

// Set request method
objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile;

// Set buffer size
int intBufferLength = 16 * 1024;
byte[] objBuffer = new byte[intBufferLength];

// Opens a file to read
FileStream objFileStream = objFile.OpenRead();
		
try
{
  // Get Stream of the file
  Stream objStream = objFTPRequest.GetRequestStream();
		
  int len = 0;
		
  while ((len = objFileStream.Read(objBuffer, 0, intBufferLength)) != 0)
  {
    // Write file Content 
    objStream.Write(objBuffer, 0, len);
    
  }
		
  objStream.Close();
  objFileStream.Close();
  
} catch (Exception ex) {

  throw ex;
  
}	

以上是关于csharp Enviar un fichero来自FTP usando C#para .NET的主要内容,如果未能解决你的问题,请参考以下文章

php 包括todos los ficheros de un directorio

Mac OS X上的Quitar acls de un fichero o directorio

php Enviar correo con el campo email de un nodo en concreto。

sh sshfs的。 Montar un sistema remoto de ficheros en local mediante el comando ssh en linux。

sh sshfs的。 Montar un sistema remoto de ficheros en local mediante el comando ssh en linux。

csharp itinerar a traves de un diccionario