作为我项目的一部分,我必须压缩包含文件的本地文件夹,然后将此zip文件夹上传到FTP服务器。
或
上传文件夹后是否可以在FTP服务器上压缩文件夹(我的意思是上传文件夹中的单个文件)
你能告诉我怎么做到这一点吗?
以下是我正在使用的源代码
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp_server/1.zip");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
// Copy the contents of the file to the request stream.
//StreamReader sourceStream = new StreamReader(@"C:\Track\FTP\FTPApplication\FTPApplication\testfile.txt");
StreamReader sourceStream = new StreamReader("1.zip");
byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
你能告诉我如何做到这一点吗?
谢谢, 希狄。