Home > other >  C # FTP download file, the file named in Chinese to make mistakes
C # FTP download file, the file named in Chinese to make mistakes

Time:10-06

Private void the Download (string filePath string fileName)
{

//Encoding.
fileName=HttpUtility. UrlEncode (fileName, Encoding UTF8). The ToString ();//file transcoding

F=new the FileInfo (@ "D://" + fileName);

FtpWebRequest reqFTP;

Try
{

FileStream outputStream=new FileStream (filePath + "\ " + fileName, FileMode. Create);

ReqFTP=(FtpWebRequest) FtpWebRequest. Create (new Uri (" ftp://"+ ftpSeverIP +"/" + fileName));

ReqFTP. Method=WebRequestMethods. Ftp. DownloadFile;

ReqFTP. UseBinary=true;

ReqFTP. Credentials=new NetworkCredential (ftpUserID ftpPassword);

FtpWebResponse response=(FtpWebResponse) reqFTP. The method GetResponse ();

Stream ftpStream=response. GetResponseStream ();

Long cl=response. ContentLength;

Int bufferSize=2048;

Int readCount;

Byte [] buffer=new byte [bufferSize];

ReadCount=ftpStream. Read (buffer, 0, bufferSize);

OutputStream=f. reate ();

While (readCount & gt; 0)
{
OutputStream. Write (buffer, 0, readCount);

ReadCount=ftpStream. Read (buffer, 0, bufferSize);


}

FtpStream. Close ();

OutputStream. Close ();

The response. The Close ();

The Debug Log (" chenggong ");
Isfailed=false;
}
The catch (Exception ex)
{
Isfailed=true;
The Debug Log (ex. Message);
Exa=ex. The Message;
}
}


I have done a transcoding, but don't know is correct
  • Related