C # File Upload-ignore Byte encoding format

Source: Internet
Author: User

# Region ftp upload function

/// <Summary>
/// Ftp upload function
/// </Summary>
/// <Param name = "ftpServerIP"> </param>
/// <Param name = "filename"> </param>
/// <Param name = "ftpUserID"> </param>
/// <Param name = "ftpPassword"> </param>
Public static void Upload (string ftpServerIP, string filename, string ftpUserID, string ftpPassword)
{
FileInfo fileInf = new FileInfo (filename );

String uri = "ftp: //" + ftpServerIP + "/" + fileInf. Name;
FtpWebRequest reqFTP;

// Create an FtpWebRequest object based on the uri
ReqFTP = (FtpWebRequest) FtpWebRequest. Create (new Uri ("ftp: //" + ftpServerIP + "/" + fileInf. Name ));

// Ftp user name and password
ReqFTP. Credentials = new NetworkCredential (ftpUserID, ftpPassword );

// The default value is true, and the connection will not be closed
// Executed after a command
ReqFTP. KeepAlive = false;

// Specify the command to be executed
ReqFTP. Method = WebRequestMethods. Ftp. UploadFile;

// Specify the data transmission type
ReqFTP. UseBinary = true;

// Notify the server of the file size when uploading the file
ReqFTP. ContentLength = fileInf. Length;

// Set the buffer size to 2 kb.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.